Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feat] support alert notice #4782

Merged
merged 41 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f2b75da
add dependency
tomsun28 Jun 26, 2023
51d498f
init alert notice
tomsun28 Jun 28, 2023
a5eac35
Merge branch 'master' into feature-alertnotice
tomsun28 Jun 28, 2023
5125710
init alert receiver controller api
tomsun28 Jun 29, 2023
b631718
alert notice
tomsun28 Jun 29, 2023
2308295
delete unused alert template
tomsun28 Jun 29, 2023
d56252a
Merge branch 'master' into feature-alertnotice
tomsun28 Jun 29, 2023
0cb3b34
fix pmd error
tomsun28 Jun 29, 2023
f2ee261
support alarm sender in gateway plugins
tomsun28 Jul 23, 2023
49cc97e
add license header
tomsun28 Jul 23, 2023
f5ed76d
Merge branch 'master' into feature-alertnotice
tomsun28 Jul 23, 2023
6407d4e
pass pmd
tomsun28 Jul 26, 2023
382cb20
pass pmd
tomsun28 Jul 27, 2023
f65b1a1
Merge branch 'master' into feature-alertnotice
tomsun28 Aug 10, 2023
b12c42d
bugfix error typehandler
tomsun28 Aug 10, 2023
2492e28
bugfix error unit test
tomsun28 Aug 10, 2023
5da4898
fix pmd error
tomsun28 Aug 10, 2023
6f5d6ec
fix pmd error
tomsun28 Aug 10, 2023
5dbfecd
fix pmd error
tomsun28 Aug 10, 2023
d190430
Merge branch 'master' into feature-alertnotice
ywj1352 Aug 16, 2023
771869b
Merge branch 'master' into feature-alertnotice
tomsun28 Aug 24, 2023
514a822
add db init table sql
tomsun28 Aug 24, 2023
23dc7dd
[Improve] delete alert support batch (#1)
VampireAchao Sep 2, 2023
25dd243
support send receiver test message controller
tomsun28 Sep 3, 2023
d858212
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 3, 2023
421dc41
fix pmd error
tomsun28 Sep 3, 2023
75d33a8
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 3, 2023
0f51566
ignore alert report auth
tomsun28 Sep 3, 2023
145f883
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 6, 2023
53998bd
add alarmLowWarning alarmMediumCritical alarmHighEmergency
tomsun28 Sep 6, 2023
b8bbabb
fix e2e test error
tomsun28 Sep 6, 2023
675ab09
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 6, 2023
86a5560
update report url in docker-compose env
tomsun28 Sep 6, 2023
09fdb3a
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 7, 2023
0f23166
fix test error
tomsun28 Sep 7, 2023
7d549b1
fix test error
tomsun28 Sep 7, 2023
4e0aa7c
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 7, 2023
801d5e2
fix test error
tomsun28 Sep 7, 2023
b062f4c
Merge branch 'master' into feature-alertnotice
moremind Sep 8, 2023
f5382df
Merge branch 'master' into feature-alertnotice
tomsun28 Sep 8, 2023
349c6e9
Merge branch 'master' into feature-alertnotice
moremind Sep 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1989,4 +1989,38 @@ CREATE TABLE `tag_relation`
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;



-- ----------------------------
-- Table structure for alert_receiver
-- ----------------------------
DROP TABLE IF EXISTS `alert_receiver`;
CREATE TABLE IF NOT EXISTS `alert_receiver`
(
`id` varchar(128) NOT NULL COMMENT 'primary key id',
`name` varchar(255) NOT NULL COMMENT 'name',
`enable` tinyint(4) NOT NULL COMMENT 'enable or not',
`type` tinyint(4) NOT NULL COMMENT 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat',
`phone` varchar(255) COMMENT 'phone',
`email` varchar(255) COMMENT 'email',
`hook_url` varchar(255) COMMENT 'hook url',
`wechat_id` varchar(255) COMMENT 'wechat id',
`access_token` varchar(255) COMMENT 'access token',
`tg_bot_token` varchar(255) COMMENT 'tg bot token',
`tg_user_id` varchar(255) COMMENT 'tg user id',
`slack_web_hook_url` varchar(255) COMMENT 'slack web hook url',
`corp_id` varchar(255) COMMENT 'corp id',
`agent_id` varchar(255) COMMENT 'agent id',
`app_secret` varchar(255) COMMENT 'app secret',
`discord_channel_id` varchar(255) COMMENT 'discord channel id',
`discord_bot_token` varchar(255) COMMENT 'discord bot token',
`smn_ak` varchar(255) COMMENT 'smn ak',
`smn_sk` varchar(255) COMMENT 'smn sk',
`smn_project_id` varchar(255) COMMENT 'smn project id',
`smn_region` varchar(255) COMMENT 'smn region',
`smn_topic_urn` varchar(255) COMMENT 'smn topic urn',
`match_all` tinyint(4) NOT NULL COMMENT 'match all or not',
`labels` varchar(255) COMMENT 'labels',
`levels` varchar(255) COMMENT 'levels',
`date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time',
`date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
42 changes: 42 additions & 0 deletions db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2411,3 +2411,45 @@ COMMENT ON COLUMN "public"."alert_template"."content" IS 'alert template content
COMMENT ON COLUMN "public"."alert_template"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_template"."date_updated" IS 'update time';

-- ----------------------------
-- Table structure for alert_receiver
-- ----------------------------
DROP TABLE IF EXISTS "public"."alert_receiver";
CREATE TABLE "public"."alert_receiver"
(
"id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
"name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
"enable" int4 NOT NULL,
"type" int4 NOT NULL,
"phone" varchar(255) COLLATE "pg_catalog"."default",
"email" varchar(255) COLLATE "pg_catalog"."default",
"hook_url" varchar(255) COLLATE "pg_catalog"."default",
"wechat_id" varchar(255) COLLATE "pg_catalog"."default",
"access_token" varchar(255) COLLATE "pg_catalog"."default",
"tg_bot_token" varchar(255) COLLATE "pg_catalog"."default",
"tg_user_id" varchar(255) COLLATE "pg_catalog"."default",
"slack_web_hook_url" varchar(255) COLLATE "pg_catalog"."default",
"corp_id" varchar(255) COLLATE "pg_catalog"."default",
"agent_id" varchar(255) COLLATE "pg_catalog"."default",
"app_secret" varchar(255) COLLATE "pg_catalog"."default",
"discord_channel_id" varchar(255) COLLATE "pg_catalog"."default",
"discord_bot_token" varchar(255) COLLATE "pg_catalog"."default",
"smn_ak" varchar(255) COLLATE "pg_catalog"."default",
"smn_sk" varchar(255) COLLATE "pg_catalog"."default",
"smn_project_id" varchar(255) COLLATE "pg_catalog"."default",
"smn_region" varchar(255) COLLATE "pg_catalog"."default",
"smn_topic_urn" varchar(255) COLLATE "pg_catalog"."default",
"match_all" int4 NOT NULL,
"labels" varchar(255) COLLATE "pg_catalog"."default",
"levels" varchar(255) COLLATE "pg_catalog"."default",
"date_created" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone),
"date_updated" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone)
)
;
COMMENT ON COLUMN "public"."alert_receiver"."id" IS 'primary key id';
COMMENT ON COLUMN "public"."alert_receiver"."name" IS 'alarm receiver name';
COMMENT ON COLUMN "public"."alert_receiver"."enable" IS 'enable or not';
COMMENT ON COLUMN "public"."alert_receiver"."type" IS 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat';
COMMENT ON COLUMN "public"."alert_receiver"."match_all" IS 'match all or not';
COMMENT ON COLUMN "public"."alert_receiver"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';
64 changes: 64 additions & 0 deletions db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2513,3 +2513,67 @@ on column ALTER_TEMPLATE.date_created
comment
on column ALTER_TEMPLATE.date_updated
is 'update time';

-- ----------------------------
-- Table structure for alert_receiver
-- ----------------------------
create table alert_receiver
(
id varchar(128) not null,
name varchar(255) not null,
enable NUMBER(10) not null,
type NUMBER(10) not null,
phone varchar(255),
email varchar(255),
hook_url varchar(255),
wechat_id varchar(255),
access_token varchar(255),
tg_bot_token varchar(255),
tg_user_id varchar(255),
slack_web_hook_url varchar(255),
corp_id varchar(255),
agent_id varchar(255),
app_secret varchar(255),
discord_channel_id varchar(255),
discord_bot_token varchar(255),
smn_ak varchar(255),
smn_sk varchar(255),
smn_project_id varchar(255),
smn_region varchar(255),
smn_topic_urn varchar(255),
match_all NUMBER(10),
labels varchar(255),
levels varchar(255),
date_created timestamp(3) default SYSDATE not null,
date_updated timestamp(3) default SYSDATE not null,
PRIMARY KEY (id)
)
;
-- Add comments to the columns
comment
on column alert_receiver.id
is 'primary key id';
comment
on column alert_receiver.name
is 'alert receiver name';
comment
on column alert_receiver.enable
is 'enable or not';
comment
on column alert_receiver.type
is 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat';
comment
on column alert_receiver.match_all
is 'enable or not';
comment
on column alert_receiver.labels
is 'alarm labels';
comment
on column alert_receiver.levels
is 'alarm levels';
comment
on column alert_receiver.date_created
is 'create time';
comment
on column alert_receiver.date_updated
is 'update time';
42 changes: 42 additions & 0 deletions db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2408,3 +2408,45 @@ COMMENT ON COLUMN "public"."alert_template"."content" IS 'alert template content
COMMENT ON COLUMN "public"."alert_template"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_template"."date_updated" IS 'update time';

-- ----------------------------
-- Table structure for alert_receiver
-- ----------------------------
DROP TABLE IF EXISTS "public"."alert_receiver";
CREATE TABLE "public"."alert_receiver"
(
"id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
"name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
"enable" int4 NOT NULL,
"type" int4 NOT NULL,
"phone" varchar(255) COLLATE "pg_catalog"."default",
"email" varchar(255) COLLATE "pg_catalog"."default",
"hook_url" varchar(255) COLLATE "pg_catalog"."default",
"wechat_id" varchar(255) COLLATE "pg_catalog"."default",
"access_token" varchar(255) COLLATE "pg_catalog"."default",
"tg_bot_token" varchar(255) COLLATE "pg_catalog"."default",
"tg_user_id" varchar(255) COLLATE "pg_catalog"."default",
"slack_web_hook_url" varchar(255) COLLATE "pg_catalog"."default",
"corp_id" varchar(255) COLLATE "pg_catalog"."default",
"agent_id" varchar(255) COLLATE "pg_catalog"."default",
"app_secret" varchar(255) COLLATE "pg_catalog"."default",
"discord_channel_id" varchar(255) COLLATE "pg_catalog"."default",
"discord_bot_token" varchar(255) COLLATE "pg_catalog"."default",
"smn_ak" varchar(255) COLLATE "pg_catalog"."default",
"smn_sk" varchar(255) COLLATE "pg_catalog"."default",
"smn_project_id" varchar(255) COLLATE "pg_catalog"."default",
"smn_region" varchar(255) COLLATE "pg_catalog"."default",
"smn_topic_urn" varchar(255) COLLATE "pg_catalog"."default",
"match_all" int4 NOT NULL,
"labels" varchar(255) COLLATE "pg_catalog"."default",
"levels" varchar(255) COLLATE "pg_catalog"."default",
"date_created" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone),
"date_updated" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone)
)
;
COMMENT ON COLUMN "public"."alert_receiver"."id" IS 'primary key id';
COMMENT ON COLUMN "public"."alert_receiver"."name" IS 'alarm receiver name';
COMMENT ON COLUMN "public"."alert_receiver"."enable" IS 'enable or not';
COMMENT ON COLUMN "public"."alert_receiver"."type" IS 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat';
COMMENT ON COLUMN "public"."alert_receiver"."match_all" IS 'match all or not';
COMMENT ON COLUMN "public"."alert_receiver"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';
6 changes: 6 additions & 0 deletions shenyu-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-alert</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.shenyu.admin.controller;

import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageParameter;
import org.apache.shenyu.admin.model.query.AlertReceiverQuery;
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
import org.apache.shenyu.admin.service.AlertReceiverService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
import org.apache.shenyu.alert.model.AlertReceiverDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Alert Receiver Controller.
*/
@Validated
@RestController
@RequestMapping("/alert/receiver")
public class AlertReceiverController {

@Autowired
private AlertReceiverService alertReceiverService;

/**
* add new alert receiver.
*
* @param alertReceiverDTO alertReceiverDTO
* @return result
*/
@PostMapping
public ShenyuAdminResult addReceiver(@Valid @RequestBody final AlertReceiverDTO alertReceiverDTO) {
alertReceiverService.addReceiver(alertReceiverDTO);
return ShenyuAdminResult.success(ShenyuResultMessage.CREATE_SUCCESS);
}

/**
* update alert receiver.
*
* @param alertReceiverDTO alertReceiverDTO
* @return result
*/
@PutMapping
public ShenyuAdminResult editReceiver(@Valid @RequestBody final AlertReceiverDTO alertReceiverDTO) {
alertReceiverService.updateReceiver(alertReceiverDTO);
return ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS);
}

/**
* delete alert receiver.
*
* @param ids primary key.
* @return result
*/
@DeleteMapping("/batch")
public ShenyuAdminResult deleteReceiver(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
alertReceiverService.deleteReceiver(ids);
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS);
}

/**
* delete alert receiver.
*
* @param id alertReceiver ID
* @return result
*/
@GetMapping("/{id}")
public ShenyuAdminResult getReceiverDetail(@PathVariable("id") final String id) {
AlertReceiverDTO receiverDTO = alertReceiverService.detail(id);
return ShenyuAdminResult.success(receiverDTO);
}

/**
* query receiver.
* @param currentPage current page
* @param pageSize page size
* @return receiver
*/
@GetMapping
public ShenyuAdminResult getReceivers(@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize) {
CommonPager<AlertReceiverDTO> commonPager = alertReceiverService.listByPage(new AlertReceiverQuery(new PageParameter(currentPage, pageSize)));
return ShenyuAdminResult.success(commonPager);
}

/**
* send test message to receiver.
* @param alertReceiverDTO receiver
* @return send result
*/
@PostMapping(path = "/test")
public ShenyuAdminResult sendTestMsg(@Valid @RequestBody final AlertReceiverDTO alertReceiverDTO) {
try {
boolean sendFlag = alertReceiverService.sendTestMsg(alertReceiverDTO);
if (sendFlag) {
return ShenyuAdminResult.success();
} else {
return ShenyuAdminResult.error("Notify service not available, please check config!");
}
} catch (Exception e) {
return ShenyuAdminResult.error("Notify service error: " + e.getMessage());
}
}

}
Loading
Loading