feat: alert_subscribe add name and disabled (#1145)
* feat: alert_subscribe add name and disabled * feat: alert_subscribe add name and disabled Co-authored-by: tanxiao <tanxiao@asiainfo.com>
This commit is contained in:
parent
a7bad003f5
commit
23eb766c14
|
@ -288,6 +288,8 @@ CREATE TABLE `alert_mute` (
|
||||||
|
|
||||||
CREATE TABLE `alert_subscribe` (
|
CREATE TABLE `alert_subscribe` (
|
||||||
`id` bigint unsigned not null auto_increment,
|
`id` bigint unsigned not null auto_increment,
|
||||||
|
`name` varchar(255) not null default '',
|
||||||
|
`disabled` tinyint(1) not null default 0 comment '0:enabled 1:disabled',
|
||||||
`group_id` bigint not null default 0 comment 'busi group id',
|
`group_id` bigint not null default 0 comment 'busi group id',
|
||||||
`cate` varchar(128) not null,
|
`cate` varchar(128) not null,
|
||||||
`cluster` varchar(128) not null,
|
`cluster` varchar(128) not null,
|
||||||
|
|
|
@ -339,6 +339,8 @@ COMMENT ON COLUMN alert_mute.etime IS 'end time';
|
||||||
|
|
||||||
CREATE TABLE alert_subscribe (
|
CREATE TABLE alert_subscribe (
|
||||||
id bigserial,
|
id bigserial,
|
||||||
|
"name" varchar(255) NOT NULL default '',
|
||||||
|
disabled int2 NOT NULL default 0 ,
|
||||||
group_id bigint not null default 0 ,
|
group_id bigint not null default 0 ,
|
||||||
cate varchar(128) not null default '' ,
|
cate varchar(128) not null default '' ,
|
||||||
cluster varchar(128) not null,
|
cluster varchar(128) not null,
|
||||||
|
@ -357,6 +359,7 @@ CREATE TABLE alert_subscribe (
|
||||||
ALTER TABLE alert_subscribe ADD CONSTRAINT alert_subscribe_pk PRIMARY KEY (id);
|
ALTER TABLE alert_subscribe ADD CONSTRAINT alert_subscribe_pk PRIMARY KEY (id);
|
||||||
CREATE INDEX alert_subscribe_group_id_idx ON alert_subscribe (group_id);
|
CREATE INDEX alert_subscribe_group_id_idx ON alert_subscribe (group_id);
|
||||||
CREATE INDEX alert_subscribe_update_at_idx ON alert_subscribe (update_at);
|
CREATE INDEX alert_subscribe_update_at_idx ON alert_subscribe (update_at);
|
||||||
|
COMMENT ON COLUMN alert_subscribe.disabled IS '0:enabled 1:disabled';
|
||||||
COMMENT ON COLUMN alert_subscribe.group_id IS 'busi group id';
|
COMMENT ON COLUMN alert_subscribe.group_id IS 'busi group id';
|
||||||
COMMENT ON COLUMN alert_subscribe.tags IS 'json,map,tagkey->regexp|value';
|
COMMENT ON COLUMN alert_subscribe.tags IS 'json,map,tagkey->regexp|value';
|
||||||
COMMENT ON COLUMN alert_subscribe.redefine_severity IS 'is redefine severity?';
|
COMMENT ON COLUMN alert_subscribe.redefine_severity IS 'is redefine severity?';
|
||||||
|
|
|
@ -13,6 +13,8 @@ import (
|
||||||
|
|
||||||
type AlertSubscribe struct {
|
type AlertSubscribe struct {
|
||||||
Id int64 `json:"id" gorm:"primaryKey"`
|
Id int64 `json:"id" gorm:"primaryKey"`
|
||||||
|
Name string `json:"name"` // AlertSubscribe name
|
||||||
|
Disabled int `json:"disabled"` // 0: enabled, 1: disabled
|
||||||
GroupId int64 `json:"group_id"`
|
GroupId int64 `json:"group_id"`
|
||||||
Cate string `json:"cate"`
|
Cate string `json:"cate"`
|
||||||
Cluster string `json:"cluster"` // take effect by clusters, seperated by space
|
Cluster string `json:"cluster"` // take effect by clusters, seperated by space
|
||||||
|
@ -55,6 +57,10 @@ func AlertSubscribeGet(where string, args ...interface{}) (*AlertSubscribe, erro
|
||||||
return lst[0], nil
|
return lst[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AlertSubscribe) IsDisabled() bool {
|
||||||
|
return s.Disabled == 1
|
||||||
|
}
|
||||||
|
|
||||||
func (s *AlertSubscribe) Verify() error {
|
func (s *AlertSubscribe) Verify() error {
|
||||||
if s.Cluster == "" {
|
if s.Cluster == "" {
|
||||||
return errors.New("cluster invalid")
|
return errors.New("cluster invalid")
|
||||||
|
|
|
@ -351,6 +351,10 @@ func handleSubscribes(event models.AlertCurEvent, subs []*models.AlertSubscribe)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSubscribe(event models.AlertCurEvent, sub *models.AlertSubscribe) {
|
func handleSubscribe(event models.AlertCurEvent, sub *models.AlertSubscribe) {
|
||||||
|
if sub.IsDisabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !matchTags(event.TagsMap, sub.ITags) {
|
if !matchTags(event.TagsMap, sub.ITags) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ func alertSubscribePut(c *gin.Context) {
|
||||||
fs[i].UpdateBy = username
|
fs[i].UpdateBy = username
|
||||||
fs[i].UpdateAt = timestamp
|
fs[i].UpdateAt = timestamp
|
||||||
ginx.Dangerous(fs[i].Update(
|
ginx.Dangerous(fs[i].Update(
|
||||||
|
"name",
|
||||||
|
"disabled",
|
||||||
"cluster",
|
"cluster",
|
||||||
"rule_id",
|
"rule_id",
|
||||||
"tags",
|
"tags",
|
||||||
|
|
Loading…
Reference in New Issue