fix(#I12YNS): 健康日志发送到云

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I12YNS
This commit is contained in:
Argo Window10 2019-11-15 18:29:17 +08:00
parent 47bfeb59eb
commit 75bfb7881a
6 changed files with 34 additions and 17 deletions

View File

@ -35,6 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection
private readonly HttpClient httpClient;
private readonly IDisposable optionsReloadToken;
private CloudLoggerOption option;
/// <summary>
/// 构造函数
/// </summary>
@ -43,8 +44,10 @@ namespace Microsoft.Extensions.DependencyInjection
optionsReloadToken = options.OnChange(op => option = op);
option = options.CurrentValue;
httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(10);
httpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(10)
};
httpClient.DefaultRequestHeaders.Connection.Add("keep-alive");
LogCallback = new Action<string>(async message =>

View File

@ -10,6 +10,12 @@
"Default": "Error"
},
"FileName": "Error\\Log.log"
},
"Cloud": {
"LogLevel": {
"Default": "Error"
},
"Url": "https://client.sdgxgz.com/api/Interface/Log"
}
},
"ConnectionStrings": {
@ -57,9 +63,6 @@
"SwaggerPathBase": "",
"AllowOrigins": "http://localhost,http://ba.sdgxgz.cn",
"GiteeHealthChecks": false,
"CloudLoggerOption": {
"Url": ""
},
"Sentry": {
"Dsn": "https://70bdfff562e84fa7b9a43d65924ab9ad@sentry.io/1469396"
},

View File

@ -1,4 +1,9 @@
(function ($) {
$.extend({
sendHealths: function (data) {
$.bc({ url: 'http://client.sdgxgz.com/api/Interface/Log', data: JSON.stringify(data), method: 'post' });
}
});
$.fn.extend({
autoScrollSidebar: function (options) {
var option = $.extend({ target: null, offsetTop: 0 }, options);
@ -75,7 +80,7 @@
var resultFormat = {
"Success": '<span class="badge badge-pill badge-success badge-task"><i class="fa fa-check-circle"></i><span>成功</span></span>',
"Timeout": '<span class="badge badge-pill badge-warning badge-task"><i class="fa fa-exclamation-circle"></i><span>超时</span></span>'
}
};
var htmlUserTemplate = '<a class="dropdown-item position-relative" href="{0}"><span class="label label-primary"><i class="fa fa-thumb-tack"></i></span><div class="content">{1}</div><div class="small italic content-task">{2}</div>{3}</a>';
var html = result.Tasks.map(function (u) {
return $.format(htmlUserTemplate, $.formatUrl('Admin/Tasks'), u.Name, u.LastRuntime, resultFormat[u.LastRunResult]);

View File

@ -49,6 +49,8 @@
$.bc({
url: 'healths',
callback: function (result) {
// async send result to cloud
$.sendHealths(result);
var data = $.map(result.Keys, function (name) {
return { Name: name, Duration: result.Report.Entries[name].Duration, Status: result.Report.Entries[name].Status, Exception: result.Report.Entries[name].Exception, Description: result.Report.Entries[name].Description, Data: result.Report.Entries[name].Data };
});

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Bootstrap.Client.Controllers.Api
{
/// <summary>
/// 日志接口
/// 运维邮件发送接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
@ -16,12 +16,17 @@ namespace Bootstrap.Client.Controllers.Api
public class InterfaceController : ControllerBase
{
/// <summary>
/// 日志方法 异常错误记录
/// 邮件发送异常错误记录方法
/// </summary>
/// <param name="config"></param>
/// <param name="message"></param>
/// <returns></returns>
public async Task<bool> Log([FromServices]IConfiguration config, [FromBody]string message)
{
return await SendMailAsync(config, message);
}
private async Task<bool> SendMailAsync(IConfiguration config, string message)
{
var section = config.GetSection("SmtpClient");
var smtpHost = section.GetValue("Host", "smtp.163.com");
@ -29,9 +34,14 @@ namespace Bootstrap.Client.Controllers.Api
var from = section.GetValue("From", "");
var to = section.GetValue("To", "");
var mailSender = new SmtpClient(smtpHost);
mailSender.Credentials = new NetworkCredential(from, password);
await mailSender.SendMailAsync(from, to, "BootstrapAdmin Exception", message);
if (!string.IsNullOrEmpty(password))
{
using var mailSender = new SmtpClient(smtpHost)
{
Credentials = new NetworkCredential(from, password)
};
await mailSender.SendMailAsync(from, to, "BootstrapAdmin Exception", message);
}
return true;
}
}

View File

@ -47,12 +47,6 @@
"From": "honeywell_mes@163.com",
"To": "argo@163.com"
},
"DeployOptions": {
"Enabled": false,
"DeployFile": "..\\..\\..\\..\\publish.ps1",
"OSPlatform": "Windows",
"Branch": "release"
},
"AllowOrigins": "http://localhost,http://argo.zylweb.cn",
"LongbowCache": {
"Enabled": true,