|
@@ -1,5 +1,7 @@
|
|
|
using Azure.Cosmos;
|
|
|
using Azure.Storage.Blobs.Models;
|
|
|
+using DinkToPdf;
|
|
|
+using DinkToPdf.Contracts;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.Azure.Cosmos.Table;
|
|
|
using Microsoft.Azure.Functions.Worker;
|
|
@@ -32,33 +34,57 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
- public IESTimerTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
|
|
|
+ private readonly IConverter _converter;
|
|
|
+ public IESTimerTrigger(IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
|
_azureStorage = azureStorage;
|
|
|
_azureRedis = azureRedis;
|
|
|
+ _converter = converter;
|
|
|
} /// <summary>
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <param name="log"></param>
|
|
|
/// <returns></returns>
|
|
|
- //[Function("FireWallFileLog")]
|
|
|
- ////https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
|
|
|
- ////0 1 * * * * 一天中每小时的第 1 分钟
|
|
|
- ////0 */1 * * * * 每五分钟一次
|
|
|
- //public async Task FireWallFileLog([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
|
|
|
- //{
|
|
|
- // await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录(测试): {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", GroupNames.成都开发測試群組);
|
|
|
- // string location = Environment.GetEnvironmentVariable("Option:Location");
|
|
|
- // if (location.Contains("China"))
|
|
|
- // {
|
|
|
+ [Function("FireWallFileLog")]
|
|
|
+ //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
|
|
|
+ //0 1 * * * * 一天中每小时的第 1 分钟
|
|
|
+ //0 */1 * * * * 每五分钟一次
|
|
|
+ public async Task FireWallFileLog([TimerTrigger("0 1 * * * *")] TimerInfo myTimer, ILogger log)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string location = Environment.GetEnvironmentVariable("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 (location.Contains("China"))
|
|
|
+ {
|
|
|
+ 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");
|
|
|
+ if (retn.recCnts.IsNotEmpty())
|
|
|
+ {
|
|
|
+
|
|
|
+ var topApi = retn.recCnts.SelectMany(x => x.apiCnt).OrderByDescending(o => o.count).Take(5).Select(x => new { x.api, x.ip, x.count });
|
|
|
+ var topIp = retn.recCnts.SelectMany(x => x.ipCnt).OrderByDescending(o => o.count).Take(5).Select(x => new { x.api, x.ip, x.count });
|
|
|
+ //https://teammodelos.blob.core.chinacloudapi.cn/0-public/pie-borderRadius.html
|
|
|
+
|
|
|
+ await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录\n> 记录时间:{datetime.AddHours(8).ToString("yyyy-MM-dd HH")}\n> ![screenshot]()\n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [地址]({retn.saveUrls.First()}) \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.成都开发測試群組);
|
|
|
+ }
|
|
|
|
|
|
- // }
|
|
|
- // else if (location.Contains("Global")) {
|
|
|
-
|
|
|
- // }
|
|
|
- // await BILogAnalyseService.GetPathAnalyse(_azureStorage, "", "LogStorage");
|
|
|
- //}
|
|
|
+ }
|
|
|
}
|
|
|
}
|