|
@@ -95,62 +95,65 @@ 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,string path, string connectStr)
|
|
|
+ public static async Task<(List<RecCnt> recCnts, List<string> saveUrls)> GetPathAnalyse(AzureStorageFactory _azureStorage,string path, string connectName)
|
|
|
{
|
|
|
- var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectStr);
|
|
|
-
|
|
|
List<RecCnt> recCnts = new();
|
|
|
List<string> urls = new();
|
|
|
|
|
|
- await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
|
|
|
- {
|
|
|
- StringBuilder visits = new("[");
|
|
|
- //BlobClient tempBlobClient = blobClient.GetBlobClient(blobItem.Name);
|
|
|
- //BlobDownloadInfo download = tempBlobClient.Download();
|
|
|
- BlobDownloadInfo download = blobClient.GetBlobClient(blobItem.Name).Download();
|
|
|
-
|
|
|
- var content = download.Content;
|
|
|
- string text;
|
|
|
- using (var streamReader = new StreamReader(content))
|
|
|
+ try {
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectName);
|
|
|
+ await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
|
|
|
{
|
|
|
- while ((text = streamReader.ReadLine()) != null)
|
|
|
+ StringBuilder visits = new("[");
|
|
|
+ //BlobClient tempBlobClient = blobClient.GetBlobClient(blobItem.Name);
|
|
|
+ //BlobDownloadInfo download = tempBlobClient.Download();
|
|
|
+ BlobDownloadInfo download = blobClient.GetBlobClient(blobItem.Name).Download();
|
|
|
+
|
|
|
+ var content = download.Content;
|
|
|
+ string text;
|
|
|
+ using (var streamReader = new StreamReader(content))
|
|
|
{
|
|
|
- if (streamReader.EndOfStream)
|
|
|
- visits.Append($"{text.ToString()}");
|
|
|
- else
|
|
|
- visits.Append($"{text.ToString()},");
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ if (streamReader.EndOfStream)
|
|
|
+ visits.Append($"{text.ToString()}");
|
|
|
+ else
|
|
|
+ visits.Append($"{text.ToString()},");
|
|
|
+ }
|
|
|
+
|
|
|
+ visits.Append("]");
|
|
|
+ streamReader.Close();
|
|
|
}
|
|
|
|
|
|
- visits.Append("]");
|
|
|
- streamReader.Close();
|
|
|
- }
|
|
|
+ string input = visits.ToString();
|
|
|
+ List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
|
|
|
+ DateTimeOffset dtime = DateTimeOffset.UtcNow;
|
|
|
+ string cHour = dtime.ToString("yyyyMMddHH");
|
|
|
+ string cDay = dtime.ToString("yyyyMMdd");
|
|
|
+ if (aGInfos.Count > 0)
|
|
|
+ {
|
|
|
+ cHour = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMddHH")).First();
|
|
|
+ cDay = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMdd")).First();
|
|
|
+ }
|
|
|
|
|
|
- string input = visits.ToString();
|
|
|
- List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
|
|
|
- DateTimeOffset dtime = DateTimeOffset.UtcNow;
|
|
|
- string cHour = dtime.ToString("yyyyMMddHH");
|
|
|
- string cDay = dtime.ToString("yyyyMMdd");
|
|
|
- if (aGInfos.Count > 0)
|
|
|
- {
|
|
|
- cHour = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMddHH")).First();
|
|
|
- cDay = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMdd")).First();
|
|
|
- }
|
|
|
+ RecCnt saveCnts = new();
|
|
|
|
|
|
- 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 }).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 }).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;
|
|
|
|
|
|
- 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;
|
|
|
+ recCnts.Add(saveCnts);
|
|
|
|
|
|
- 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;
|
|
|
- recCnts.Add(saveCnts);
|
|
|
+ ////保存存至Blob文件
|
|
|
+ var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
|
|
|
- ////保存存至Blob文件
|
|
|
- var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
+ urls.Add(url);
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
|
- urls.Add(url);
|
|
|
}
|
|
|
|
|
|
return (recCnts, urls);
|