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
d3cc2651
Commit
d3cc2651
authored
Jul 19, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 更新预警列表
parent
10789817
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
785 additions
and
406 deletions
+785
-406
go.mod
go.mod
+40
-3
go.sum
go.sum
+392
-3
src/bean/entity/alert_webhook.go
src/bean/entity/alert_webhook.go
+7
-0
src/bean/vo/request/alert.go
src/bean/vo/request/alert.go
+7
-3
src/bean/vo/request/alert_webhook.go
src/bean/vo/request/alert_webhook.go
+75
-0
src/bean/vo/response/alert_webhook.go
src/bean/vo/response/alert_webhook.go
+13
-0
src/controller/alert.go
src/controller/alert.go
+10
-21
src/controller/alert_webhook.go
src/controller/alert_webhook.go
+41
-0
src/router/alertwebhookrouter.go.go
src/router/alertwebhookrouter.go.go
+16
-0
src/router/router.go
src/router/router.go
+2
-0
src/router/workorderrouter.go
src/router/workorderrouter.go
+1
-1
src/service/alert.go
src/service/alert.go
+176
-272
src/service/alert_webhook.go
src/service/alert_webhook.go
+5
-103
No files found.
go.mod
View file @
d3cc2651
...
@@ -20,9 +20,11 @@ require (
...
@@ -20,9 +20,11 @@ require (
github.com/lib/pq v1.10.9
github.com/lib/pq v1.10.9
github.com/minio/minio-go/v7 v7.0.58
github.com/minio/minio-go/v7 v7.0.58
github.com/mojocn/base64Captcha v1.3.5
github.com/mojocn/base64Captcha v1.3.5
github.com/olivere/elastic/v7 v7.0.32
github.com/opensearch-project/opensearch-go v1.1.0
github.com/opensearch-project/opensearch-go v1.1.0
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0
github.com/prometheus/alertmanager v0.25.0
github.com/robfig/cron v1.2.0
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/spf13/cast v1.5.0
github.com/spf13/cast v1.5.0
...
@@ -40,50 +42,85 @@ require (
...
@@ -40,50 +42,85 @@ require (
require (
require (
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/aws/aws-sdk-go v1.44.156 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/henrylee2cn/ameda v1.5.0 // indirect
github.com/henrylee2cn/ameda v1.5.0 // indirect
github.com/henrylee2cn/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/henrylee2cn/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/nyaruka/phonenumbers v1.1.7 // indirect
github.com/nyaruka/phonenumbers v1.1.7 // indirect
github.com/olivere/elastic/v7 v7.0.32 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.38.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/exporter-toolkit v0.8.2 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
go.uber.org/atomic v1.
9
.0 // indirect
go.uber.org/atomic v1.
10
.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/image v0.0.0-20190
501045829-6d32002ffd75
// indirect
golang.org/x/image v0.0.0-20190
802002840-cff245a6509b
// indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
...
...
go.sum
View file @
d3cc2651
This diff is collapsed.
Click to expand it.
src/bean/entity/alert_webhook.go
0 → 100644
View file @
d3cc2651
package
entity
import
(
"github.com/prometheus/alertmanager/notify/webhook"
)
type
Message
webhook
.
Message
src/bean/vo/request/alert.go
View file @
d3cc2651
...
@@ -9,9 +9,13 @@ type DetailAlert struct {
...
@@ -9,9 +9,13 @@ type DetailAlert struct {
}
}
type
UpdateAlert
struct
{
type
UpdateAlert
struct
{
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
Id
int
`json:"id" form:"id" binding:"required"`
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
Ids
[]
string
`json:"ids" form:"ids" binding:"required_without=Id"`
// 预警ids
Keyword
string
`json:"keyword" form:"keyword"`
// 预警点/分类/指标
CloseRemark
string
`json:"close_remark" form:"close_remark"`
// 关闭备注
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:重大风险
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
DisposalContent
string
`json:"disposal_content" form:"disposal_content"`
// 处置内容(工单管理,结果反馈)
}
}
type
BatchPushAlert
struct
{
type
BatchPushAlert
struct
{
...
...
src/bean/vo/request/alert_webhook.go
0 → 100644
View file @
d3cc2651
package
request
import
(
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
)
type
AddAlertWebhook
struct
{
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id" binding:"required_if=DetectionType 1"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name" binding:"required_if=DetectionType 2"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name" binding:"required_if=DetectionType 2"`
// 预警对象名称
MetricConfigId
string
`json:"metric_config_id" form:"'metric_config_id'" binding:"required_if=DetectionType 1"`
// 预警指标id
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(映射entity.MetricConfig.MetricName)
Expr
string
`json:"expr" form:"expr" binding:"required_if=DetectionType 2"`
// 指标表达式(PromQL语句)
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" form:"alert_condition" binding:"required,dive"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required_if=DetectionType 2"`
// 预警规则类型 关联字典表
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range" binding:"required,dive"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration" binding:"gte=0"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
NotifyMethod
[]
string
`json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"`
// 预警通知方式 dingtalk sms
NotifyRecipients
[]
entity
.
NotifyRecipients
`json:"notify_recipients" form:"notify_recipients" binding:"required,dive"`
// 预警推送用户
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count" binding:"gte=1"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"`
// 是否开启 1:是 2:否
}
type
UpdateAlertWebhook
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id" binding:"required_if=DetectionType 1"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name" binding:"required_if=DetectionType 2"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name" binding:"required_if=DetectionType 2"`
// 预警对象名称
MetricConfigId
string
`json:"metric_config_id" form:"'metric_config_id'" binding:"required_if=DetectionType 1"`
// 预警指标id
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(映射entity.MetricConfig.MetricName)
Expr
string
`json:"expr" form:"expr" binding:"required_if=DetectionType 2"`
// 指标表达式(PromQL语句)
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" form:"alert_condition" binding:"required"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required_if=DetectionType 2"`
// 预警规则类型 关联字典表
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range" binding:"required,dive"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration" binding:"gte=0"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
NotifyMethod
[]
string
`json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"`
// 预警通知方式 dingtalk sms
NotifyRecipients
[]
entity
.
NotifyRecipients
`json:"notify_recipients" form:"notify_recipients" binding:"dive"`
// 预警推送用户
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count" binding:"gte=1"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"`
// 是否开启 1:是 2:否
}
type
UpdateIsEnabledAlertWebhook
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"`
// 是否开启 1:是 2:否
}
type
DeleteAlertWebhook
struct
{
Id
string
`json:"id" form:"id"`
Ids
[]
string
`json:"ids" form:"ids" binding:"required_without=Id"`
}
type
DetailAlertWebhook
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
}
type
ListAlertWebhook
struct
{
// 请输入预警规则名称/预警对象/预警分类/预警指标
Id
string
`json:"id" form:"id"`
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"omitempty,oneof=all dingtalk sms"`
// 预警通知方式 dingtalk sms
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=1 2"`
// 是否开启 1:是 2:否
Keyword
string
`json:"keyword" form:"keyword"`
// 预警规则名称(指标名称)
StartTime
string
`json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
EndTime
string
`json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
Pagination
}
src/bean/vo/response/alert_webhook.go
0 → 100644
View file @
d3cc2651
package
response
type
AlertWebhookItem
struct
{
}
func
(
a
*
AlertWebhookItem
)
TableName
()
string
{
return
"alert_rules"
}
type
AlertWebhookList
struct
{
TotalCount
int64
`json:"total_count"`
List
[]
AlertWebhookItem
`json:"list"`
}
src/controller/alert.go
View file @
d3cc2651
...
@@ -16,13 +16,8 @@ func UpdateAlert(c *gin.Context) {
...
@@ -16,13 +16,8 @@ func UpdateAlert(c *gin.Context) {
return
return
}
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
db
,
err
:=
client
.
GetDbClient
()
err
:=
svc
.
Update
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
err
=
svc
.
Update
(
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
...
@@ -37,13 +32,13 @@ func BatchPushAlert(c *gin.Context) {
...
@@ -37,13 +32,13 @@ func BatchPushAlert(c *gin.Context) {
return
return
}
}
svc
:=
service
.
Alert
List
Svc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
return
}
}
err
=
svc
.
BatchPushAlert
List
(
db
.
NewSession
(),
req
)
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
...
@@ -58,13 +53,13 @@ func BatchCloseAlert(c *gin.Context) {
...
@@ -58,13 +53,13 @@ func BatchCloseAlert(c *gin.Context) {
return
return
}
}
svc
:=
service
.
Alert
List
Svc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
return
}
}
err
=
svc
.
BatchCloseAlert
List
(
db
.
NewSession
(),
req
)
err
=
svc
.
BatchCloseAlert
(
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
...
@@ -79,7 +74,7 @@ func DetailAlert(c *gin.Context) {
...
@@ -79,7 +74,7 @@ func DetailAlert(c *gin.Context) {
return
return
}
}
svc
:=
service
.
Alert
List
Svc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
GetDataById
(
req
)
data
,
err
:=
svc
.
GetDataById
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
...
@@ -94,7 +89,7 @@ func ListAlert(c *gin.Context) {
...
@@ -94,7 +89,7 @@ func ListAlert(c *gin.Context) {
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
return
}
}
svc
:=
service
.
Alert
List
Svc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
List
(
req
)
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
...
@@ -109,14 +104,8 @@ func DisposeAlert(c *gin.Context) {
...
@@ -109,14 +104,8 @@ func DisposeAlert(c *gin.Context) {
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
return
}
}
db
,
err
:=
client
.
GetDbClient
()
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
if
err
!=
nil
{
err
:=
svc
.
DisposeAlert
(
req
)
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
err
=
svc
.
DisposeAlertList
(
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/controller/alert_webhook.go
0 → 100644
View file @
d3cc2651
package
controller
import
(
"github.com/gin-gonic/gin"
"github.com/prometheus/alertmanager/notify/webhook"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"go.uber.org/zap"
)
// AlertWebhook 回调
func
AlertWebhook
(
c
*
gin
.
Context
)
{
// 读取请求体原始数据
var
req
webhook
.
Message
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
/*bodyBytes, err := io.ReadAll(c.Request.Body)
if err != nil {
// 处理错误
c.String(500, "Error reading request body")
return
}*/
// 输出请求体原始数据到控制台
//log.Printf("原始数据------>\n%s\n<------", string(bodyBytes))
// 将请求体数据重新放入请求中,以便后续处理
//c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
conf
.
Logger
.
Info
(
"------>webhook.Message------>"
,
zap
.
Any
(
"message"
,
req
))
/*var payload map[string]interface{}
if err := c.ShouldBind(&payload); err != nil {
log.Println("Failed to parse JSON: ", err)
SendJsonResponse(c, err, "")
}*/
SendJsonResponse
(
c
,
resp
.
OK
,
req
)
}
src/router/alertwebhookrouter.go.go
0 → 100644
View file @
d3cc2651
package
router
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitAlertWebhookRouter 初始化预警回调路由
func
InitAlertWebhookRouter
(
e
*
gin
.
Engine
)
{
group
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/alert_webhook"
,
conf
.
Options
.
Prefix
))
{
group
.
POST
(
""
,
controller
.
AlertWebhook
)
}
}
src/router/router.go
View file @
d3cc2651
...
@@ -55,6 +55,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -55,6 +55,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitMetricConfigRouter
(
r
)
InitMetricConfigRouter
(
r
)
// 初始化预警规则配置路由
// 初始化预警规则配置路由
InitAlertRulesRouter
(
r
)
InitAlertRulesRouter
(
r
)
// 初始化预警回调路由
InitAlertWebhookRouter
(
r
)
// 初始化预警列表配置路由
// 初始化预警列表配置路由
InitAlertListRouter
(
r
)
InitAlertListRouter
(
r
)
// 初始化prometheus路由
// 初始化prometheus路由
...
...
src/router/workorderrouter.go
View file @
d3cc2651
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
func
InitWorkOrderRouter
(
e
*
gin
.
Engine
)
{
func
InitWorkOrderRouter
(
e
*
gin
.
Engine
)
{
so
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/work_order"
,
conf
.
Options
.
Prefix
))
so
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/work_order"
,
conf
.
Options
.
Prefix
))
//预警工单管理
//预警工单管理
alert
:=
so
.
Group
(
"/alert"
,
header
.
SetContext
)
alert
:=
so
.
Group
(
"/alert"
)
{
{
alert
.
GET
(
""
,
controller
.
DetailAlert
)
// 详情
alert
.
GET
(
""
,
controller
.
DetailAlert
)
// 详情
alert
.
GET
(
"/list"
,
controller
.
ListAlert
)
// 列表
alert
.
GET
(
"/list"
,
controller
.
ListAlert
)
// 列表
...
...
src/service/alert
_list
.go
→
src/service/alert.go
View file @
d3cc2651
This diff is collapsed.
Click to expand it.
src/service/alert_webhook.go
View file @
d3cc2651
package
service
package
service
import
(
import
(
"github.com/
jinzhu/copier
"
"github.com/
prometheus/alertmanager/notify/webhook
"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"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/jsontime"
"xorm.io/xorm"
"xorm.io/xorm"
)
)
...
@@ -15,103 +11,9 @@ type AlertWebhookSvc struct {
...
@@ -15,103 +11,9 @@ type AlertWebhookSvc struct {
}
}
// TODO AlertManager 回调接口
// TODO AlertManager 回调接口
func
(
a
*
AlertWebhookSvc
)
WebHook
(
session
*
xorm
.
Session
,
req
request
.
AddPushRecord
)
(
id
string
,
err
error
)
{
func
(
a
*
AlertWebhookSvc
)
AlertWebhook
(
session
*
xorm
.
Session
,
req
webhook
.
Message
)
(
id
string
,
err
error
)
{
// 报警消息
// 1.判断该opensearch数据是否恢复
now
:=
jsontime
.
Now
()
// 1.1.如果恢复,则查询当前opensearch最大id值,插入新的数据到预警列表
data
:=
entity
.
PushRecord
{
// 1.2如果未恢复,根据id更新该条数据
CreatedBy
:
a
.
User
.
SystemAccount
,
CreatedAt
:
now
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
,
err
=
session
.
Insert
(
&
data
)
if
err
!=
nil
{
return
}
return
}
func
(
a
*
AlertWebhookSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdatePushRecord
)
error
{
now
:=
jsontime
.
Now
()
data
:=
entity
.
PushRecord
{
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
,
err
:=
session
.
ID
(
req
.
Id
)
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
a
*
AlertWebhookSvc
)
GetDataById
(
req
request
.
DetailPushRecord
)
(
resp
response
.
PushRecordItem
,
err
error
)
{
now
:=
jsontime
.
Time
{}
data
:=
response
.
PushRecordItem
{
PushRecord
:
entity
.
PushRecord
{
Id
:
1
,
AlertRulesId
:
"83343ef6-4a99-47bd-abb4-bcff52feb2ec"
,
RiskLevel
:
1
,
SystemAccount
:
"xiaowang"
,
PushTime
:
now
,
PushType
:
1
,
Status
:
1
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
resp
=
data
return
}
func
(
a
*
AlertWebhookSvc
)
List
(
req
request
.
ListPushRecord
)
(
resp
response
.
PushRecordList
,
err
error
)
{
now
:=
jsontime
.
Time
{}
data1
:=
response
.
PushRecordItem
{
PushRecord
:
entity
.
PushRecord
{
Id
:
1
,
AlertRulesId
:
"83343ef6-4a99-47bd-abb4-bcff52feb2ec"
,
RiskLevel
:
1
,
SystemAccount
:
"xiaowang"
,
PushTime
:
now
,
PushType
:
1
,
Status
:
1
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
data2
:=
response
.
PushRecordItem
{
PushRecord
:
entity
.
PushRecord
{
Id
:
1
,
AlertRulesId
:
"83343ef6-4a99-47bd-abb4-bcff52feb2ec"
,
RiskLevel
:
2
,
SystemAccount
:
"xiaozhang"
,
PushTime
:
now
,
PushType
:
2
,
Status
:
2
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
resp
.
List
=
append
(
resp
.
List
,
data1
,
data2
)
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
return
}
func
(
a
*
AlertWebhookSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
_
,
err
=
db
.
NewSession
()
.
In
(
"id"
,
ids
)
.
Delete
(
new
(
entity
.
PushRecord
))
return
return
}
}
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