From 5579181f54d5b3f473eb199a7912dc443d10d78d Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 5 Feb 2026 17:00:40 +0800 Subject: [PATCH 1/4] =?UTF-8?q?irc=E9=A1=B9=E7=9B=AE=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- irc_api.drone.yml | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/irc_api.drone.yml b/irc_api.drone.yml index 785ee716c..f06092d78 100644 --- a/irc_api.drone.yml +++ b/irc_api.drone.yml @@ -43,10 +43,16 @@ server: from_secret: test_ssh_pwd steps: -- name: publish-test-irc - commands: - - bash /opt/1panel/xc-deploy-new/Test_IRC_Swarm/devops-publish/test-branch-publish.sh - + - name: publish-test-irc + commands: + - bash /opt/1panel/xc-deploy-new/Test_IRC_Swarm/devops-publish/test-branch-publish.sh + - name: notify-wecom + commands: + - bash /opt/1panel/xc-deploy-new/devops-center/drone-notify-wecom.sh "$DRONE_BUILD_STATUS" "$DRONE_REPO_NAME" "$DRONE_BRANCH" "$DRONE_BUILD_NUMBER" "4355b98e-1e72-4678-8dfb-2fc6ad0bf449" "$DRONE_COMMIT_MESSAGE" "$DRONE_COMMIT_AUTHOR" "Test_IRC_API Test_IRC_SCP_API" "irc.test.extimaging.com" + when: + status: + - success + - failure trigger: branch: - Test_IRC_Net8 @@ -81,32 +87,7 @@ trigger: branch: - Test_Study_Net8 ---- -kind: pipeline -type: ssh -name: ssh-linux-test-hir -platform: - os: Linux - arch: 386 - -clone: - disable: true #禁用默认克隆 - -server: - host: 106.14.89.110 - user: root - password: - from_secret: test_ssh_pwd - -steps: -- name: publish-test-hir - commands: - - bash /opt/1panel/xc-deploy-new/Test_HIR/devops-publish/test-branch-publish.sh - -trigger: - branch: - - Test_HIR From 7e13edc440e0d72c616355b487efb922b404faed Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 5 Feb 2026 23:20:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RequestResponseLoggingMiddleware.cs | 2 + IRaCIS.Core.API/appsettings.json | 6 +- .../ProjectExceptionFilter.cs | 31 ++++++- .../Helper/OtherTool/WeComNotifier.cs | 87 +++++++++++++++++++ IRaCIS.Core.Application/TestService.cs | 6 +- 5 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs diff --git a/IRaCIS.Core.API/_PipelineExtensions/Serilog/RequestResponseLoggingMiddleware.cs b/IRaCIS.Core.API/_PipelineExtensions/Serilog/RequestResponseLoggingMiddleware.cs index ee61eabbc..c1686fd55 100644 --- a/IRaCIS.Core.API/_PipelineExtensions/Serilog/RequestResponseLoggingMiddleware.cs +++ b/IRaCIS.Core.API/_PipelineExtensions/Serilog/RequestResponseLoggingMiddleware.cs @@ -39,6 +39,8 @@ namespace IRaCIS.Core.API._PipelineExtensions.Serilog var requestBodyPayload = await ReadRequestBody(context.Request); + context.Items["RequestBody"] = requestBodyPayload; + using (LogContext.PushProperty("RequestBody", requestBodyPayload)) { //await _next.Invoke() diff --git a/IRaCIS.Core.API/appsettings.json b/IRaCIS.Core.API/appsettings.json index 5376f4890..46d4d60fe 100644 --- a/IRaCIS.Core.API/appsettings.json +++ b/IRaCIS.Core.API/appsettings.json @@ -3,7 +3,7 @@ "SecurityKey": "ShangHaiZhanYing_SecurityKey_SHzyyl@2021", "Issuer": "Extimaging", "Audience": "EICS", - "TokenExpireMinute": "10080"//7天 + "TokenExpireMinute": "10080" //7天 }, "IpRateLimiting": { "EnableEndpointRateLimiting": true, @@ -43,6 +43,10 @@ } ] }, + "WeComNoticeConfig": { + "WebhookUrl": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4355b98e-1e72-4678-8dfb-2fc6ad0bf449", //4355b98e-1e72-4678-8dfb-2fc6ad0bf449 //cdd97aab-d256-4f07-9145-a0a2b1555322 + "NoticeUserList": [ "ZhouHang" ] + }, "IRaCISImageStore": { "SwitchingMode": "RemainingDiskCapacity", "SwitchingRatio": 80, diff --git a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs index 930c3d9cb..3231e9059 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs +++ b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs @@ -1,13 +1,16 @@ -using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Application.Helper.OtherTool; +using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; namespace IRaCIS.Core.Application.Filter; -public class ProjectExceptionFilter(ILogger _logger, IStringLocalizer _localizer) : Attribute, IExceptionFilter +public class ProjectExceptionFilter(ILogger _logger, IStringLocalizer _localizer, IConfiguration _config, IUserInfo _userInfo) : Attribute, IExceptionFilter { public void OnException(ExceptionContext context) @@ -48,6 +51,29 @@ public class ProjectExceptionFilter(ILogger _logger, ISt context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["Project_ExceptionContactDeveloper"] + (exception.InnerException is null ? (exception.Message) : (exception.Message + "Inner ExceptionMsg:" + exception.InnerException?.Message)), ApiResponseCodeEnum.ProgramException)); + try + { + string webhook = _config["WeComNoticeConfig:WebhookUrl"] ?? string.Empty; + var uri = new Uri(_config["SystemEmailSendConfig:SiteUrl"]); + var baseUrl = uri.GetLeftPart(UriPartial.Authority); + + var userList = _config.GetSection("WeComNoticeConfig:NoticeUserList").Get(); + + + + var requestBody = context.HttpContext.Items["RequestBody"] as string; + + + + + WeComNotifier.SendErrorAsync(webhook, baseUrl, $"{_userInfo.UserName}({_userInfo.UserTypeShortName})", context.HttpContext.Request.Path, requestBody, exception, userList).GetAwaiter().GetResult(); + } + catch (Exception ex) + { + + _logger.LogError($"异常过滤器里发送企业微信出现错误:{ex.Message}"); + } + } context.ExceptionHandled = true;//标记当前异常已经被处理过了 @@ -58,6 +84,7 @@ public class ProjectExceptionFilter(ILogger _logger, ISt _logger.LogError(errorInfo); + //_logger.LogError(exception, exception.Message); } else diff --git a/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs new file mode 100644 index 000000000..71395135f --- /dev/null +++ b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using RestSharp; +using System.Net; +using System.Threading.Tasks; +using IdentityModel; + +namespace IRaCIS.Core.Application.Helper.OtherTool; + + + +public static class WeComNotifier +{ + + public static async Task SendErrorAsync(string webhook, string env, string userName,string api,string json, Exception ex, params string[] atUsers) + { + try + { + var client = new RestClient(); + var request = new RestRequest(webhook, Method.Post); + + string hostName = Dns.GetHostName(); + string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + var stack = ex.StackTrace ?? "无堆栈信息"; + stack = stack.Replace("\n", "\n> "); // 每行变成引用,防止markdown断裂 + if (stack.Length > 1000) + stack = stack.Substring(0, 1000) + "...(已截断)"; + + string atText = ""; + if (atUsers != null && atUsers.Any()) + { + foreach (var u in atUsers) + { + atText += $" <@{u}>"; // 注意空格分隔 + } + } + + + //> **运行环境:** < font color = ""comment"" >{ EnvironmentName} danger danger warning + var markdown = $@"## 🚨 系统异常告警 + > {atText} + > **部署环境:** [{env}]({env}) + > **服务器:** {hostName} + > **发生时间:** {time} + > **操作人:** {userName} + > **接口地址:** {api} + ### ❗ 异常信息 + {ex.Message} + >**📦 请求数据(JSON 格式):** +```json +{json} +``` + ### 堆栈信息(部分) + > {stack} + "; + + var payload = new + { + msgtype = "markdown", + markdown = new + { + content = markdown + } + }; + + request.AddHeader("Content-Type", "application/json"); + request.AddStringBody(JsonConvert.SerializeObject(payload), DataFormat.Json); + + var response = await client.ExecuteAsync(request); + + if (!response.IsSuccessful) + { + Log.Logger.Error($"企业微信通知失败: {response.StatusCode} {response.ErrorMessage}"); + } + } + catch (Exception notifyEx) + { + Log.Logger.Error("发送企业微信告警异常: " + notifyEx.Message); + } + } +} + diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 5d65f40dc..591a1ec2a 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -6,6 +6,7 @@ using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.BusinessFilter; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Application.Helper.OtherTool; using IRaCIS.Core.Application.Service.BusinessFilter; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain; @@ -109,10 +110,13 @@ namespace IRaCIS.Core.Application.Service //创建一个模型验证的方法 [AllowAnonymous] - [HttpPost] + [HttpPost("{email}")] public async Task PostModelVerify(ModelVerifyCommand modelVerify) { + var webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cdd97aab-d256-4f07-9145-a0a2b1555322"; + //await WeComNotifier.SendErrorAsync(webhook, "http://irc.test.extimaging.com/login", new Exception("测试异常"), new[] { "ZhouHang" }); + throw new Exception("手动测试异常抛出"); return ResponseOutput.Ok(modelVerify); } From 570318cf3bfa742218fae21f014a2e23d865df00 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 5 Feb 2026 23:28:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A0=86=E6=A0=88?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs index 71395135f..641b117b1 100644 --- a/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs +++ b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs @@ -28,8 +28,8 @@ public static class WeComNotifier var stack = ex.StackTrace ?? "无堆栈信息"; stack = stack.Replace("\n", "\n> "); // 每行变成引用,防止markdown断裂 - if (stack.Length > 1000) - stack = stack.Substring(0, 1000) + "...(已截断)"; + if (stack.Length > 1200) + stack = stack.Substring(0, 1200) + "...(已截断)"; string atText = ""; if (atUsers != null && atUsers.Any()) From 37e8545eba115a333dd4b49b4f955a2d035f449a Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 6 Feb 2026 21:12:52 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E9=80=9A=E7=9F=A5=E6=8E=A7=E5=88=B6=E5=BC=80?= =?UTF-8?q?=E5=85=B3=EF=BC=8C=E5=90=8C=E6=97=B6=E5=89=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=88=86=E5=88=AB=E9=80=9A=E7=9F=A5=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=9A=84=E4=BA=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/appsettings.json | 4 +- .../LegacyController/ModelActionFilter .cs | 51 +++++++++- .../ProjectExceptionFilter.cs | 30 ++++-- .../Helper/OtherTool/WeComNotifier.cs | 95 +++++++++++-------- IRaCIS.Core.Application/TestService.cs | 2 +- 5 files changed, 128 insertions(+), 54 deletions(-) diff --git a/IRaCIS.Core.API/appsettings.json b/IRaCIS.Core.API/appsettings.json index 46d4d60fe..a39b1b988 100644 --- a/IRaCIS.Core.API/appsettings.json +++ b/IRaCIS.Core.API/appsettings.json @@ -44,8 +44,10 @@ ] }, "WeComNoticeConfig": { + "IsOpenWeComNotice": true, "WebhookUrl": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4355b98e-1e72-4678-8dfb-2fc6ad0bf449", //4355b98e-1e72-4678-8dfb-2fc6ad0bf449 //cdd97aab-d256-4f07-9145-a0a2b1555322 - "NoticeUserList": [ "ZhouHang" ] + "APINoticeUserList": [ "ZhouHang" ], + "VueNoticeUserList": [ "wangxiaoshuang" ] }, "IRaCISImageStore": { "SwitchingMode": "RemainingDiskCapacity", diff --git a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ModelActionFilter .cs b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ModelActionFilter .cs index ee1d392cf..65552ebcf 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ModelActionFilter .cs +++ b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ModelActionFilter .cs @@ -1,18 +1,22 @@ -using Microsoft.AspNetCore.Mvc; +using IRaCIS.Core.Application.Helper.OtherTool; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Localization; using Newtonsoft.Json; +using System; using System.Reflection; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace IRaCIS.Core.Application.Filter; -public class ModelActionFilter(IStringLocalizer _localizer) : ActionFilterAttribute, IActionFilter +public class ModelActionFilter(IStringLocalizer _localizer, IConfiguration _config, IUserInfo _userInfo) : ActionFilterAttribute, IActionFilter { @@ -27,6 +31,49 @@ public class ModelActionFilter(IStringLocalizer _localizer) : ActionFilterAttrib .Select(e => e.ErrorMessage) .ToArray(); + var request = context.HttpContext.Request; + + try + { + bool isOpenWeComNotice = _config.GetValue("WeComNoticeConfig:IsOpenWeComNotice"); + + if (isOpenWeComNotice) + { + string webhook = _config["WeComNoticeConfig:WebhookUrl"] ?? string.Empty; + + var uri = new Uri(_config["SystemEmailSendConfig:SiteUrl"]); + var baseUrl = uri.GetLeftPart(UriPartial.Authority); + + var userList = _config.GetSection("WeComNoticeConfig:VueNoticeUserList").Get(); + + var requestBody = context.HttpContext.Items["RequestBody"] as string; + + + // 🔔 异步告警(不要阻塞请求) + _ = WeComNotifier.SendAlertAsync( + webhook: webhook, + alert: new WeComAlert + { + Env = baseUrl, + UserName = _userInfo.UserName.IsNotNullOrEmpty()? $"{_userInfo.UserName}({_userInfo.UserTypeShortName})": "匿名", + Api = $"{request.Method} {request.Path}", + Message = $"前端传递参数,后端模型验证失败\n 具体信息:{JsonConvert.SerializeObject(validationErrors)}", + JsonData = requestBody, + AtUsers = userList ?? [] + } + ); + + } + + + } + catch (Exception ex) + { + Log.Logger.Error($"模型验证过滤器里发送企业微信出现错误:{ex.Message}"); + } + + + //---提供给接口的参数无效。 context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["ModelAction_InvalidAPIParameter"] + JsonConvert.SerializeObject(validationErrors))); } diff --git a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs index 3231e9059..eeb70dcc9 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs +++ b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs @@ -53,27 +53,41 @@ public class ProjectExceptionFilter(ILogger _logger, ISt try { - string webhook = _config["WeComNoticeConfig:WebhookUrl"] ?? string.Empty; - var uri = new Uri(_config["SystemEmailSendConfig:SiteUrl"]); - var baseUrl = uri.GetLeftPart(UriPartial.Authority); + bool isOpenWeComNotice = _config.GetValue("WeComNoticeConfig:IsOpenWeComNotice"); - var userList = _config.GetSection("WeComNoticeConfig:NoticeUserList").Get(); + if (isOpenWeComNotice) + { + string webhook = _config["WeComNoticeConfig:WebhookUrl"] ?? string.Empty; + var uri = new Uri(_config["SystemEmailSendConfig:SiteUrl"]); + var baseUrl = uri.GetLeftPart(UriPartial.Authority); + var userList = _config.GetSection("WeComNoticeConfig:APINoticeUserList").Get(); - var requestBody = context.HttpContext.Items["RequestBody"] as string; + var requestBody = context.HttpContext.Items["RequestBody"] as string; + var alert = new WeComAlert + { + Env = baseUrl, + UserName = $"{_userInfo.UserName}({_userInfo.UserTypeShortName})", + Api = context.HttpContext.Request.Path, + Message = exception.Message, + JsonData = requestBody, + Stack = exception.StackTrace, + AtUsers = userList ?? [] + }; + _ = WeComNotifier.SendAlertAsync(webhook, alert); + } - - WeComNotifier.SendErrorAsync(webhook, baseUrl, $"{_userInfo.UserName}({_userInfo.UserTypeShortName})", context.HttpContext.Request.Path, requestBody, exception, userList).GetAwaiter().GetResult(); + } catch (Exception ex) { _logger.LogError($"异常过滤器里发送企业微信出现错误:{ex.Message}"); } - + } context.ExceptionHandled = true;//标记当前异常已经被处理过了 diff --git a/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs index 641b117b1..db100aa68 100644 --- a/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs +++ b/IRaCIS.Core.Application/Helper/OtherTool/WeComNotifier.cs @@ -12,76 +12,87 @@ using IdentityModel; namespace IRaCIS.Core.Application.Helper.OtherTool; +public class WeComAlert +{ + public string Env { get; set; } = ""; + public string UserName { get; set; } = ""; + public string Api { get; set; } = ""; + public string Message { get; set; } = ""; + public string? JsonData { get; set; } + public string? Stack { get; set; } + public bool HasStack => !string.IsNullOrWhiteSpace(Stack); + public string[] AtUsers { get; set; } = []; +} + + public static class WeComNotifier { - - public static async Task SendErrorAsync(string webhook, string env, string userName,string api,string json, Exception ex, params string[] atUsers) + + public static async Task SendAlertAsync(string webhook, WeComAlert alert) { try { var client = new RestClient(); var request = new RestRequest(webhook, Method.Post); - string hostName = Dns.GetHostName(); - string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - var stack = ex.StackTrace ?? "无堆栈信息"; - stack = stack.Replace("\n", "\n> "); // 每行变成引用,防止markdown断裂 - if (stack.Length > 1200) - stack = stack.Substring(0, 1200) + "...(已截断)"; + // 处理 @ + var atText = alert.AtUsers != null && alert.AtUsers.Any() + ? string.Join("", alert.AtUsers.Select(u => $" <@{u}>")) + : ""; - string atText = ""; - if (atUsers != null && atUsers.Any()) + // 处理堆栈 + var stack = alert.Stack; + if (!string.IsNullOrWhiteSpace(stack)) { - foreach (var u in atUsers) - { - atText += $" <@{u}>"; // 注意空格分隔 - } + stack = stack.Replace("\n", "\n> "); + if (stack.Length > 1200) + stack = stack[..1200] + "...(已截断)"; } + var markdown = $@"## 🚨 系统告警 +> {atText} +> **部署环境:** [{alert.Env}]({alert.Env}) +> **发生时间:** {time} +> **操作人:** {alert.UserName} +> **接口地址:** {alert.Api} +### ❗ 告警信息 +{alert.Message}"; - //> **运行环境:** < font color = ""comment"" >{ EnvironmentName} danger danger warning - var markdown = $@"## 🚨 系统异常告警 - > {atText} - > **部署环境:** [{env}]({env}) - > **服务器:** {hostName} - > **发生时间:** {time} - > **操作人:** {userName} - > **接口地址:** {api} - ### ❗ 异常信息 - {ex.Message} - >**📦 请求数据(JSON 格式):** + if (!string.IsNullOrWhiteSpace(alert.JsonData)) + { + markdown += $@" +> **📦 请求数据(JSON 格式):** ```json -{json} -``` - ### 堆栈信息(部分) - > {stack} - "; +{alert.JsonData} +```"; + } + + if (!string.IsNullOrWhiteSpace(stack)) + { + markdown += $@" +### 堆栈信息(部分) +{stack}"; + } var payload = new { msgtype = "markdown", - markdown = new - { - content = markdown - } + markdown = new { content = markdown } }; request.AddHeader("Content-Type", "application/json"); request.AddStringBody(JsonConvert.SerializeObject(payload), DataFormat.Json); - var response = await client.ExecuteAsync(request); - - if (!response.IsSuccessful) - { - Log.Logger.Error($"企业微信通知失败: {response.StatusCode} {response.ErrorMessage}"); - } + await client.ExecuteAsync(request); } - catch (Exception notifyEx) + catch (Exception ex) { - Log.Logger.Error("发送企业微信告警异常: " + notifyEx.Message); + Log.Logger.Error("企业微信告警发送失败: " + ex.Message); } } + } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 591a1ec2a..a4ce65daf 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -116,7 +116,7 @@ namespace IRaCIS.Core.Application.Service var webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cdd97aab-d256-4f07-9145-a0a2b1555322"; //await WeComNotifier.SendErrorAsync(webhook, "http://irc.test.extimaging.com/login", new Exception("测试异常"), new[] { "ZhouHang" }); - throw new Exception("手动测试异常抛出"); + //throw new Exception("手动测试异常抛出"); return ResponseOutput.Ok(modelVerify); }