Browse Source

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

CrazyIter_Bin 2 years ago
parent
commit
b737dc61f5

+ 0 - 1
TEAMModelBI/Controllers/BIBlob/AnalyseFileController.cs

@@ -34,7 +34,6 @@ namespace TEAMModelBI.Controllers.BIBlob
             _azureStorage = azureStorage;
         }
 
-
         /// <summary>
         /// 查询一天的分析防火墙分析  已对接
         /// </summary>

+ 9 - 10
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -1325,6 +1325,7 @@ namespace TEAMModelBI.Controllers.BITest
         public async Task<IActionResult> GetLogAnalyse(JsonElement jsonElement)
         {
             if (!jsonElement.TryGetProperty("path", out JsonElement path)) return BadRequest();
+            if (!jsonElement.TryGetProperty("timeType", out JsonElement jTimeType)) return BadRequest();
 
             List<string> filename = new();
             ////删除过期Blob 文件
@@ -1343,7 +1344,7 @@ namespace TEAMModelBI.Controllers.BITest
             //    }
             //}
 
-            var (an, saveUrl) = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, $"{path}", BIConst.LogChina);
+            var (an, saveUrl) = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, $"{path}", BIConst.LogChina, timeType:$"{jTimeType}");
 
             return Ok(new { state = RespondCode.Ok, cnt = filename.Count, filename, an, saveUrl });
         }
@@ -1367,6 +1368,7 @@ namespace TEAMModelBI.Controllers.BITest
             var d = datetime.Day >= 10 ? $"{datetime.Day}" : $"0{datetime.Day}";
             var h = datetime.Hour >= 10 ? $"{datetime.Hour}" : $"0{datetime.Hour}";
 
+            
             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, _ipSearcher, _dingDing, path, BIConst.LogChina);
             if (retn.recCnts.IsNotEmpty())
@@ -1397,8 +1399,6 @@ namespace TEAMModelBI.Controllers.BITest
                 await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 测试(小时)-防火墙日志记录\n> 记录时间:{datetime.AddHours(8).ToString("yyyy-MM-dd HH")}\n> ![screenshot]({image})\n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" +
                     $" [发布地址]({publishUrl}) \n", GroupNames.醍摩豆服務運維群組);
             }
-            List<RecCnt> recCnts = new();
-            List<string> saveUrls = new();
 
             if (h.Equals("00"))
             {
@@ -1408,13 +1408,13 @@ namespace TEAMModelBI.Controllers.BITest
                 var ptD = pastTime.Day >= 10 ? $"{pastTime.Day}" : $"0{pastTime.Day}";
 
                 string dayPath = $"resourceId=/SUBSCRIPTIONS/73B7F9EF-D8B7-4444-9E8D-D80B43BF3CD4/RESOURCEGROUPS/TEAMMODELCHENGDU/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/OSFIREWARE/y={ptY}/m={ptM}/d={ptD}";
-                (recCnts, saveUrls) = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, dayPath, BIConst.LogChina);
+                var dayRetn = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, dayPath, BIConst.LogChina, timeType: "Day");
 
-                if (recCnts.IsNotEmpty())
+                if (dayRetn.recCnts.IsNotEmpty())
                 {
                     //一天的统计
-                    string dayPublishUrl = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={HttpUtility.UrlEncode(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={saveUrls.First()}&time={pastTime.ToString("yyyy年MM月dd日")}";
+                    string dayPublishUrl = $"https://teammodelos.blob.core.chinacloudapi.cn/0-public/api-count.html?url={HttpUtility.UrlEncode(dayRetn.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={dayRetn.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 = "";
 
@@ -1429,12 +1429,11 @@ namespace TEAMModelBI.Controllers.BITest
                         }
                     }
 
-                    await _dingDing.SendBotMarkdown("测试-防火墙日志记录", $"#### 测试(天)-防火墙日志记录\n> 记录时间:{pastTime.ToString("yyyy-MM-dd")}\n> ![screenshot]({dayImage})\n> ###### 发布时间:{pastTime.ToString("yyyy-MM-dd HH:mm:ss")}" +$" [发布地址]({dayPublishUrl}) \n", GroupNames.成都开发測試群組);
-
+                    await _dingDing.SendBotMarkdown("测试-防火墙日志记录", $"#### 测试(天)-防火墙日志记录\n> 记录时间:{pastTime.AddHours(2).ToString("yyyy-MM-dd")}\n> ![screenshot]({dayImage})\n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" +$" [发布地址]({dayPublishUrl}) \n", GroupNames.成都开发測試群組);
                 }
             }
 
-            return Ok(new { state = 200, recCnts });
+            return Ok(new { state = 200});
         }
 
 

+ 18 - 0
TEAMModelBI/TEAMModelBI.csproj

@@ -38,6 +38,24 @@
 		<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
 	</PropertyGroup>
 
+	<PropertyGroup>
+		<!-- Typescript/Javascript Client Configuration -->
+		<SpaRoot>ClientApp\</SpaRoot>
+		<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
+		<UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
+		<Version>5.2207.27</Version>
+		<AssemblyVersion>5.2207.27.1</AssemblyVersion>
+		<FileVersion>5.2207.27.1</FileVersion>
+		<Description>TEAMModelBI(BI)</Description>
+		<PackageReleaseNotes>BI版本说明版本切换标记202200701</PackageReleaseNotes>
+		<PackageId>TEAMModelBI</PackageId>
+		<Authors>teammodel</Authors>
+		<Company>醍摩豆(成都)信息技术有限公司</Company>
+		<Product>TEAMModelBI</Product>
+		<Copyright>© 2021 HABOOK Group 醍摩豆</Copyright>
+		<PackageProjectUrl>https://www.teammodel.cn</PackageProjectUrl>
+	</PropertyGroup>
+
 	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
 		<WarningLevel>4</WarningLevel>
 	</PropertyGroup>

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

@@ -119,7 +119,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                         var ptD = pastTime.Day >= 10 ? $"{pastTime.Day}" : $"0{pastTime.Day}";
 
                         string dayPath = $"resourceId=/SUBSCRIPTIONS/73B7F9EF-D8B7-4444-9E8D-D80B43BF3CD4/RESOURCEGROUPS/TEAMMODELCHENGDU/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/OSFIREWARE/y={ptY}/m={ptM}/d={ptD}";
-                        var retnDay = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, dayPath, "LogStorage");
+                        var retnDay = await BILogAnalyseService.GetPathAnalyse(_azureStorage, _ipSearcher, _dingDing, dayPath, "LogStorage",timeType:"Day");
 
                         if (retn.recCnts.IsNotEmpty()) 
                         {
@@ -144,7 +144,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                             }
                             catch (Exception ex) { }
 
-                            await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录(天)\n> 记录时间:{pastTime.ToString("yyyy-MM-dd")}\n> ![screenshot]({dayImage})\n> ###### 发布时间:{pastTime.ToString("yyyy-MM-dd HH:mm:ss")}" + $" [发布地址]({dayPublishUrl}) \n", GroupNames.成都开发測試群組);
+                            await _dingDing.SendBotMarkdown("防火墙日志记录", $"#### 防火墙日志记录(天)\n> 记录时间:{pastTime.ToString("yyyy-MM-dd")}\n> ![screenshot]({dayImage})\n> ###### 发布时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}" + $" [发布地址]({dayPublishUrl}) \n", GroupNames.成都开发測試群組);
                         }
                     }
                 }

+ 102 - 26
TEAMModelOS.SDK/Models/Service/BI/BILogAnalyseService.cs

@@ -97,15 +97,24 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="path">防火墙路径</param>
         /// <param name="connectStr">连接字串</param>
         /// <returns></returns>
-        public static async Task<(List<RecCnt> recCnts, List<string> saveUrls)> GetPathAnalyse(AzureStorageFactory _azureStorage,IPSearcher _ipSearcher,DingDing _dingDing, string path, string connectName)
-        {
+        public static async Task<(List<RecCnt> recCnts, List<string> saveUrls)> GetPathAnalyse(AzureStorageFactory _azureStorage, IPSearcher _ipSearcher, DingDing _dingDing, string path, string connectName, string timeType = "Hour")
+         {
             List<RecCnt> recCnts = new();
             List<string> urls = new();
 
             DateTimeOffset dtime = DateTimeOffset.UtcNow;
             string cDay = dtime.ToString("yyyyMMdd");
 
-            try {
+            //天api
+            List<RecApiCnt> dayApiCnt = new();
+            //天ip
+            List<RecIpCnt> dayIpCnt = new();
+
+            //天
+            List<MinuteCnt> dayCnts = new();
+
+            try 
+            {
                 var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectName);
                 await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
                 {
@@ -163,20 +172,90 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
                     RecCnt saveCnts = new();
 
-                    List<RecAppGWInfo> recInfo = aGInfos.Select(s => new RecAppGWInfo { hour = cHour, ip = s.properties.clientIp, api = s.properties.requestUri.Split("?").ToList().Count() > 1 ? s.properties.requestUri.Split("?").ToList()[0] : s.properties.requestUri, hostName = s.properties.hostname,minute = DateTimeOffset.Parse(s.time).ToString("mm") }).ToList();
+                    List<RecAppGWInfo> recInfo = aGInfos.Select(s => new RecAppGWInfo { hour = cHour, ip = s.properties.clientIp, api = s.properties.requestUri.Split("?").ToList().Count() > 1 ? s.properties.requestUri.Split("?").ToList()[0] : s.properties.requestUri, hostName = s.properties.hostname,minute = DateTimeOffset.Parse(s.time).ToString("mm")}).ToList();
 
-                    List<RecApiCnt> apiCnt = recInfo.GroupBy(a => a.api).Select(g => new RecApiCnt { api = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
-                    saveCnts.apiCnt = apiCnt;
+                    if (timeType.Equals("Hour"))
+                    {
+                        //小时
+                        List<RecApiCnt> apiCnt = recInfo.GroupBy(a => a.api).Select(g => new RecApiCnt { api = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
+                        saveCnts.apiCnt = apiCnt;
 
-                    List<RecIpCnt> ipCnt = recInfo.GroupBy(a => a.ip).Select(g => new RecIpCnt { ip = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
-                    saveCnts.ipCnt = ipCnt;
 
-                    List<MinuteCnt> minCnts = recInfo.GroupBy(a => a.minute).Select(s => new MinuteCnt { minute = s.Key, cnt = s.Count() }).ToList();                  
-                    saveCnts.minCnts = minCnts;
+                        List<RecIpCnt> ipCnt = recInfo.GroupBy(a => a.ip).Select(g => new RecIpCnt { ip = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
+                        saveCnts.ipCnt = ipCnt;
 
-                    var ipcounts = saveCnts.ipCnt.Select(z => new IdCodeCount { id = z.ip, count = z.count }).ToList();
+                        List<MinuteCnt> minCnts = recInfo.GroupBy(a => a.minute).Select(s => new MinuteCnt { minute = s.Key, cnt = s.Count() }).ToList();
+                        saveCnts.minCnts = minCnts;
+
+                        var ipcounts = saveCnts.ipCnt.Select(z => new IdCodeCount { id = z.ip, count = z.count }).ToList();
+                        ipcounts.ForEach(async x => {
+                            string region = await _ipSearcher.SearchIpAsync(x.id);
+                            if (!string.IsNullOrWhiteSpace(region))
+                            {
+                                string[] dis = region.Split("·");
+                                if (dis.Length >= 2)
+                                {
+                                    x.code = dis[dis.Length - 1];
+                                    x.name = dis[dis.Length - 2];  // 不保留省份
+                                                                   //x.name = region.Substring(0, region.LastIndexOf("·"));  //保留省份
+                                }
+                                else
+                                {
+                                    var disrs = Regex.Split(region.TrimStart().TrimEnd(), @"\s+");
+                                    if (disrs.Length >= 2)
+                                    {
+                                        x.code = disrs[disrs.Length - 1];
+                                        x.name = disrs[disrs.Length - 2];   //不保留省份
+                                                                            //x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
+                                    }
+                                    else
+                                    {
+                                        x.code = region;
+                                        x.name = region;
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                x.name = x.id;
+                                x.code = x.id;
+                            }
+                        });
+                        List<RecRegionCnt> regionCnts = new();
+                        ipcounts.GroupBy(x => x.name).ToList().ForEach(z => {
+                            regionCnts.Add(new RecRegionCnt { region = z.Key, count = z.ToList().Sum(y => y.count), hour = cHour });
+                        });
+                        saveCnts.regionCnts = regionCnts;
+                        recCnts.Add(saveCnts);
+                        //保存存至Blob文件
+                        var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHH}.json");
+                        urls.Add(url);
+                    }
+                    else if (timeType.Equals("Day"))
+                    {
+                        //天
+                        List<RecApiCnt> tempApiCnt = recInfo.GroupBy(a => a.api).Select(g => new RecApiCnt { api = g.Key, count = g.Count(), hour = cDay, hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
+                        dayApiCnt.AddRange(tempApiCnt);
+
+                        //天
+                        List<RecIpCnt> tempIpCnt = recInfo.GroupBy(a => a.ip).Select(g => new RecIpCnt { ip = g.Key, count = g.Count(), hour = cDay, hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
+                        dayIpCnt.AddRange(tempIpCnt);
+
+                        dayCnts.Add(new MinuteCnt { minute = cHH, cnt = recInfo.Count });
+                    }
+                }
+
+                if (timeType.Equals("Day"))
+                {
+                    RecCnt dayRecCnt = new();
+                    dayRecCnt.apiCnt = dayApiCnt.GroupBy(g => g.api).Select(s => new RecApiCnt { api = s.Key, count = s.Sum(gsc => gsc.count), hour = cDay, hostName = s.Select(hn => hn.hostName).FirstOrDefault(), ip = s.Select(i => i.ip).FirstOrDefault() }).ToList();
+
+                    dayRecCnt.ipCnt = dayIpCnt.GroupBy(g => g.ip).Select(s => new RecIpCnt { ip = s.Key, count = s.Sum(gsc => gsc.count), hour = cDay, hostName = s.Select(hn => hn.hostName).FirstOrDefault(), api = s.Select(i => i.api).FirstOrDefault() }).ToList();
+                    dayRecCnt.minCnts = dayCnts;
+
+                    var ipcounts = dayIpCnt.Select(z => new IdCodeCount { id = z.ip, count = z.count }).ToList();
                     ipcounts.ForEach(async x => {
-                        string region =await _ipSearcher.SearchIpAsync(x.id);
+                        string region = await _ipSearcher.SearchIpAsync(x.id);
                         if (!string.IsNullOrWhiteSpace(region))
                         {
                             string[] dis = region.Split("·");
@@ -186,7 +265,8 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                 x.name = dis[dis.Length - 2];  // 不保留省份
                                 //x.name = region.Substring(0, region.LastIndexOf("·"));  //保留省份
                             }
-                            else {
+                            else
+                            {
                                 var disrs = Regex.Split(region.TrimStart().TrimEnd(), @"\s+");
                                 if (disrs.Length >= 2)
                                 {
@@ -194,33 +274,29 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                     x.name = disrs[disrs.Length - 2];   //不保留省份
                                     //x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
                                 }
-                                else {
+                                else
+                                {
                                     x.code = region;
                                     x.name = region;
                                 }
                             }
                         }
-                        else {
+                        else
+                        {
                             x.name = x.id;
                             x.code = x.id;
                         }
                     });
-                    List<RecRegionCnt> regionCnts = new List<RecRegionCnt>();
+                    List<RecRegionCnt> regionCnts = new();
                     ipcounts.GroupBy(x => x.name).ToList().ForEach(z => {
-                        regionCnts.Add(new RecRegionCnt { region = z.Key, count = z.ToList().Sum(y => y.count), hour = cHour });
+                        regionCnts.Add(new RecRegionCnt { region = z.Key, count = z.ToList().Sum(y => y.count), hour = cDay });
                     });
-                    saveCnts.regionCnts = regionCnts;
-                    recCnts.Add(saveCnts);
+                    dayRecCnt.regionCnts = regionCnts;
+                    recCnts.Add(dayRecCnt);
                     //保存存至Blob文件
-                    var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHH}.json");
+                    var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(dayRecCnt.ToJsonString(), $"visitCnt/{cDay}", $"days.json");
                     urls.Add(url);
                 }
-
-                if (recCnts.Count > 1) 
-                {
-                    //保存一天的数据至Blob文件
-                    var daysUrl = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(recCnts.ToJsonString(), $"visitCnt/{cDay}", $"days.json");
-                }
                 
                 var azureClient = _azureStorage.GetBlobContainerClient("0-public");//获取容器连接地址
                 int expireTime = int.Parse(DateTimeOffset.UtcNow.AddDays(-180).ToString("yyyyMMdd"));