CrazyIter_Bin 2 年之前
父节点
当前提交
ccf35d2176
共有 1 个文件被更改,包括 23 次插入2 次删除
  1. 23 2
      TEAMModelOS.FunctionV4/TimeTrigger/IESTimerTrigger.cs

+ 23 - 2
TEAMModelOS.FunctionV4/TimeTrigger/IESTimerTrigger.cs

@@ -13,6 +13,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Net;
+using System.Net.Http;
 using System.Reflection;
 using System.Text;
 using System.Text.Json;
@@ -41,7 +42,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         private readonly AzureRedisFactory _azureRedis;
         private readonly IConverter _converter;
         private readonly SnowflakeId _snowflakeId;
-        public IESTimerTrigger(SnowflakeId snowflakeId,IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
+        private readonly HttpClient _httpClient;
+        public IESTimerTrigger(HttpClient httpClient,SnowflakeId snowflakeId,IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
@@ -49,6 +51,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             _azureRedis = azureRedis;
             _converter = converter;
             _snowflakeId=snowflakeId;
+            _httpClient = httpClient;
         }
         /// <summary>
         /// 防火墙日志记录文件
@@ -60,7 +63,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
         //0 1 * * * * 一天中每小时的第 1 分钟
         //0 */10 * * * *  每五分钟一次
-        public async Task FireWallFileLog([TimerTrigger("0 */10 * * * *")] TimerInfo myTimer, ILogger log)
+        public async Task FireWallFileLog([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
         {
             try
             {
@@ -70,7 +73,12 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                 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";
                     var retn = await BILogAnalyseService.GetPathAnalyse(_azureStorage, path, "LogStorage");
@@ -80,6 +88,19 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                          
                         //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=980&url={HttpUtility.UrlEncode(ulrs,Encoding.UTF8)}&delay=5000";
+                        try
+                        {
+                            string strs = await _httpClient.GetStringAsync(ulr);
+                            if (!string.IsNullOrWhiteSpace(strs)) {
+                                JsonElement json = strs.ToObject<JsonElement>();
+                                json.TryGetProperty("url", out JsonElement base64);
+                            }
+                        }
+                        catch (Exception ex) { 
+                          
+                        }
                         await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录\n> 记录时间:{datetime.AddHours(8).ToString("yyyy-MM-dd HH")}\n> ![screenshot]()\n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" +
                             $" [发布地址]({publishUrl}) \n", GroupNames.成都开发測試群組);
                     }