|
@@ -97,15 +97,24 @@ namespace TEAMModelOS.SDK.Models.Service.BI
|
|
/// <param name="path">防火墙路径</param>
|
|
/// <param name="path">防火墙路径</param>
|
|
/// <param name="connectStr">连接字串</param>
|
|
/// <param name="connectStr">连接字串</param>
|
|
/// <returns></returns>
|
|
/// <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<RecCnt> recCnts = new();
|
|
List<string> urls = new();
|
|
List<string> urls = new();
|
|
|
|
|
|
DateTimeOffset dtime = DateTimeOffset.UtcNow;
|
|
DateTimeOffset dtime = DateTimeOffset.UtcNow;
|
|
string cDay = dtime.ToString("yyyyMMdd");
|
|
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);
|
|
var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectName);
|
|
await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
|
|
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();
|
|
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 => {
|
|
ipcounts.ForEach(async x => {
|
|
- string region =await _ipSearcher.SearchIpAsync(x.id);
|
|
|
|
|
|
+ string region = await _ipSearcher.SearchIpAsync(x.id);
|
|
if (!string.IsNullOrWhiteSpace(region))
|
|
if (!string.IsNullOrWhiteSpace(region))
|
|
{
|
|
{
|
|
string[] dis = region.Split("·");
|
|
string[] dis = region.Split("·");
|
|
@@ -186,7 +265,8 @@ namespace TEAMModelOS.SDK.Models.Service.BI
|
|
x.name = dis[dis.Length - 2]; // 不保留省份
|
|
x.name = dis[dis.Length - 2]; // 不保留省份
|
|
//x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
|
|
//x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
var disrs = Regex.Split(region.TrimStart().TrimEnd(), @"\s+");
|
|
var disrs = Regex.Split(region.TrimStart().TrimEnd(), @"\s+");
|
|
if (disrs.Length >= 2)
|
|
if (disrs.Length >= 2)
|
|
{
|
|
{
|
|
@@ -194,33 +274,29 @@ namespace TEAMModelOS.SDK.Models.Service.BI
|
|
x.name = disrs[disrs.Length - 2]; //不保留省份
|
|
x.name = disrs[disrs.Length - 2]; //不保留省份
|
|
//x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
|
|
//x.name = region.Substring(0, region.LastIndexOf("·")); //保留省份
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
x.code = region;
|
|
x.code = region;
|
|
x.name = region;
|
|
x.name = region;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
x.name = x.id;
|
|
x.name = x.id;
|
|
x.code = x.id;
|
|
x.code = x.id;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- List<RecRegionCnt> regionCnts = new List<RecRegionCnt>();
|
|
|
|
|
|
+ List<RecRegionCnt> regionCnts = new();
|
|
ipcounts.GroupBy(x => x.name).ToList().ForEach(z => {
|
|
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文件
|
|
//保存存至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);
|
|
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");//获取容器连接地址
|
|
var azureClient = _azureStorage.GetBlobContainerClient("0-public");//获取容器连接地址
|
|
int expireTime = int.Parse(DateTimeOffset.UtcNow.AddDays(-180).ToString("yyyyMMdd"));
|
|
int expireTime = int.Parse(DateTimeOffset.UtcNow.AddDays(-180).ToString("yyyyMMdd"));
|