|
@@ -24,6 +24,7 @@ using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Web;
|
|
|
using TEAMModelOS.Filter;
|
|
|
using TEAMModelOS.Models;
|
|
|
using TEAMModelOS.SDK;
|
|
@@ -32,6 +33,7 @@ using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.School;
|
|
|
+using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.XTest
|
|
|
{
|
|
@@ -42,16 +44,123 @@ namespace TEAMModelOS.Controllers.XTest
|
|
|
[ApiController]
|
|
|
public class BillController : ControllerBase
|
|
|
{
|
|
|
-
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
private readonly IHttpClientFactory _httpClient;
|
|
|
private readonly IConfiguration _configuration;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
- public BillController(IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage)
|
|
|
+ private readonly IPSearcher _ipSearcher;
|
|
|
+ private readonly Option _option;
|
|
|
+ public BillController(IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage, IPSearcher searcher, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
{
|
|
|
_httpClient = httpClient;
|
|
|
_configuration = configuration;
|
|
|
_azureStorage = azureStorage;
|
|
|
+ _ipSearcher = searcher;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option.Value;
|
|
|
+ }
|
|
|
+ [HttpGet("data")]
|
|
|
+ [RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
|
+ public async Task<IActionResult> data(JsonElement j1son) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string location = _option.Location;
|
|
|
+ var datetime = DateTimeOffset.UtcNow.AddHours(-1);
|
|
|
+ var y = datetime.Year;
|
|
|
+ var m = datetime.Month >= 10 ? $"{datetime.Month}" : $"0{datetime.Month}";
|
|
|
+ var d = datetime.Day >= 10 ? $"{datetime.Day}" : $"0{datetime.Day}";
|
|
|
+ var h = datetime.Hour >= 10 ? $"{datetime.Hour}" : $"0{datetime.Hour}";
|
|
|
+#if DEBUG
|
|
|
+ if (location.Equals("China-Dep"))
|
|
|
+#else
|
|
|
+ if (location.Equals("China"))
|
|
|
+#endif
|
|
|
+
|
|
|
+ {
|
|
|
+ //string path = $"resourceId=/SUBSCRIPTIONS/73B7F9EF-D8B7-4444-9E8D-D80B43BF3CD4/RESOURCEGROUPS/TEAMMODELCHENGDU/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/OSFIREWARE/y={y}/m={m}/d={d}/h={h}/m=00/PT1H.json";
|
|
|
+ string path = $"resourceId=/SUBSCRIPTIONS/73B7F9EF-D8B7-4444-9E8D-D80B43BF3CD4/RESOURCEGROUPS/TEAMMODELCHENGDU/PROVIDERS/MICROSOFT.WEB/SITES/TEAMMODELOS/y={y}/m={m}/d={d}/h={h}/m=00/PT1H.json";
|
|
|
+ var retn = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, path, "LogStorage");
|
|
|
+ if (retn.recCnts.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //https://teammodelos.blob.core.chinacloudapi.cn/0-public/pie-borderRadius.html
|
|
|
+ string publishUrl = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={HttpUtility.UrlEncode(retn.saveUrls.First(), Encoding.UTF8)}&time={HttpUtility.UrlEncode(datetime.AddHours(8).ToString("yyyy年MM月dd日 HH时"), Encoding.UTF8)}";
|
|
|
+ string ulrs = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={retn.saveUrls.First()}&time={datetime.AddHours(8).ToString("yyyy年MM月dd日 HH时")}";
|
|
|
+ string ulr = $"http://cdhabook.teammodel.cn:8805/screen/screenshot-png?width=1920&height=1450&url={HttpUtility.UrlEncode(ulrs, Encoding.UTF8)}&delay=5000";
|
|
|
+ string image = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string strs = await _httpClient.CreateClient().GetStringAsync(ulr);
|
|
|
+ if (!string.IsNullOrWhiteSpace(strs))
|
|
|
+ {
|
|
|
+ JsonElement json = strs.ToObject<JsonElement>();
|
|
|
+ json.TryGetProperty("url", out JsonElement base64);
|
|
|
+ using (MemoryStream ms = new MemoryStream(Convert.FromBase64String($"{base64}")))
|
|
|
+ {
|
|
|
+ image = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(ms, $"visitCnt/{y}{m}{d}", $"{y}{m}{d}{h}.png", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录(小时)\n> 记录时间:{datetime.AddHours(8).ToString("yyyy-MM-dd HH")}\n> \n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" +
|
|
|
+ $" [发布地址]({publishUrl}) \n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理昨天的防火墙日志
|
|
|
+ if (h.Equals("00"))
|
|
|
+ {
|
|
|
+ var pastTime = datetime.AddHours(-1);
|
|
|
+ var ptY = pastTime.Year;
|
|
|
+ var ptM = pastTime.Month >= 10 ? $"{pastTime.Month}" : $"0{pastTime.Month}";
|
|
|
+ var ptD = pastTime.Day >= 10 ? $"{pastTime.Day}" : $"0{pastTime.Day}";
|
|
|
+
|
|
|
+ string dayPath = $"resourceId=/SUBSCRIPTIONS/73B7F9EF-D8B7-4444-9E8D-D80B43BF3CD4/RESOURCEGROUPS/TEAMMODELCHENGDU/PROVIDERS/MICROSOFT.WEB/SITES/TEAMMODELOS/y={ptY}/m={ptM}/d={ptD}";
|
|
|
+ var retnDay = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, dayPath, "LogStorage", timeType: "Day");
|
|
|
+
|
|
|
+ if (retn.recCnts.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //一天的统计
|
|
|
+ string dayPublishUrl = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={HttpUtility.UrlEncode(retnDay.saveUrls.First(), Encoding.UTF8)}&time={HttpUtility.UrlEncode(pastTime.ToString("yyyy年MM月dd日"), Encoding.UTF8)}";
|
|
|
+ string dayUrls = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={retnDay.saveUrls.First()}&time={pastTime.ToString("yyyy年MM月dd日")}";
|
|
|
+ string dayUrl = $"http://cdhabook.teammodel.cn:8805/screen/screenshot-png?width=1920&height=1450&url={HttpUtility.UrlEncode(dayUrls, Encoding.UTF8)}&delay=6000";
|
|
|
+ string dayImage = "";
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string dayStr = await _httpClient.CreateClient().GetStringAsync(dayUrl);
|
|
|
+ if (!string.IsNullOrWhiteSpace(dayStr))
|
|
|
+ {
|
|
|
+ JsonElement dayJson = dayStr.ToObject<JsonElement>();
|
|
|
+ dayJson.TryGetProperty("url", out JsonElement dayBase64);
|
|
|
+ using (MemoryStream dayMs = new(Convert.FromBase64String($"{dayBase64}")))
|
|
|
+ {
|
|
|
+ dayImage = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(dayMs, $"visitCnt/{ptY}{ptM}{ptD}", "days.png", false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex) { }
|
|
|
+ await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录(天)\n> 记录时间:{pastTime.AddHours(8).ToString("yyyy-MM-dd")}\n> \n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" +
|
|
|
+ $" [发布地址]({dayPublishUrl}) \n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (location.Contains("Global"))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ // await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
[HttpPost("report")]
|
|
|
[RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
|
public async Task<IActionResult> Report(JsonElement json)
|