Refactor Citrix virtual session data collection
This commit is contained in:
@@ -3825,77 +3825,42 @@ namespace C4IT.DataHistoryProvider
|
||||
|
||||
try
|
||||
{
|
||||
var Age2 = Age;
|
||||
if (Ids.Count == 1)
|
||||
Age2 = 365;
|
||||
var AgentLimit = DateTime.UtcNow + TimeSpan.FromDays(-Age2);
|
||||
|
||||
var idInput = Ids.Select(v => new cF4sdIdentityEntry() { Id = v, Class = infoClass }).ToList();
|
||||
var listIds = await getConnectorIdList(idInput, Token, requestInfo, LogDeep + 1);
|
||||
|
||||
if (listIds == null || listIds.Count == 0)
|
||||
var _relationService = GetStagedRelationService();
|
||||
if (_relationService == null)
|
||||
return null;
|
||||
|
||||
var lstAgentIds = new Dictionary<int, cDataHistoryUsageIdInfo>(Ids.Count);
|
||||
var lstTicketIds = new List<cF4sdConnectorIds>(Ids.Count);
|
||||
|
||||
foreach (var Entry in listIds)
|
||||
var _relatedTo = new List<cFasdApiSearchResultEntry>();
|
||||
foreach (var _idEntry in Ids)
|
||||
{
|
||||
if (M42WpmCollector != null && infoClass == enumFasdInformationClass.User)
|
||||
var _rel = new cFasdApiSearchResultEntry()
|
||||
{
|
||||
if (Entry.sid != null)
|
||||
lstTicketIds.Add(Entry);
|
||||
}
|
||||
if (Entry.lastSeenByAgent != null && Entry.lastSeenByAgent >= AgentLimit)
|
||||
{
|
||||
if (Entry.agentId2 != null)
|
||||
lstAgentIds[(int)Entry.agentId2] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.Azure };
|
||||
if (Entry.agentId != null)
|
||||
lstAgentIds[(int)Entry.agentId] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.AD };
|
||||
}
|
||||
if (Entry.localAgentIds != null)
|
||||
{
|
||||
foreach (var entryLocal in Entry.localAgentIds)
|
||||
{
|
||||
if (entryLocal.lastSeenByAgent >= AgentLimit)
|
||||
lstAgentIds[entryLocal.agentId] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.Local, account = entryLocal.account, domain = "" };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (DefaultLogger.IsDebug)
|
||||
{
|
||||
var _msgDebug = new List<string>()
|
||||
{
|
||||
$"{lstAgentIds?.Count} agent ids found by usage determination:"
|
||||
Type = cFasdApiSearchResultEntry.getSearchClass(infoClass),
|
||||
id = _idEntry
|
||||
};
|
||||
foreach (var dbgEntry in lstAgentIds)
|
||||
_msgDebug.Add($"{dbgEntry.Key}: accountType={dbgEntry.Value.AccountType}, account={dbgEntry.Value.account}, domain={dbgEntry.Value.domain}, id={dbgEntry.Value.Id}");
|
||||
DefaultLogger.LogList(LogLevels.Debug, _msgDebug);
|
||||
_relatedTo.Add(_rel);
|
||||
}
|
||||
|
||||
var taskList = new List<Task<List<cF4sdApiSearchResultRelation>>>(2);
|
||||
if (lstAgentIds.Count > 0)
|
||||
taskList.Add(Task.Run<List<cF4sdApiSearchResultRelation>>(async () => { return await GetUsedInfoFromAgentData(infoClass, lstAgentIds, Age, Token, requestInfo, LogDeep + 1); }));
|
||||
if (lstTicketIds.Count > 0)
|
||||
taskList.Add(Task.Run<List<cF4sdApiSearchResultRelation>>(async () => { return await getTicketUsage(infoClass, lstTicketIds, Age, Token, requestInfo, LogDeep + 1); }));
|
||||
|
||||
if (taskList.Count == 0)
|
||||
var taskId = await _relationService.StartGatheringRelatedObjects(_relatedTo, Age);
|
||||
if (Token.IsCancellationRequested)
|
||||
return null;
|
||||
|
||||
var arrTask = taskList.ToArray();
|
||||
var RetVal = await Task.WhenAll<List<cF4sdApiSearchResultRelation>>(arrTask);
|
||||
|
||||
var RetVal2 = new List<cF4sdApiSearchResultRelation>();
|
||||
foreach (var Entry in RetVal)
|
||||
var _retVal = new List<cF4sdApiSearchResultRelation>();
|
||||
do
|
||||
{
|
||||
if (Entry != null)
|
||||
RetVal2.AddRange(Entry);
|
||||
}
|
||||
var _rels = await _relationService.GetRelatedObjectsAsync(taskId.Id, Token);
|
||||
if (Token.IsCancellationRequested)
|
||||
return null;
|
||||
if (_rels == null)
|
||||
return null;
|
||||
|
||||
_retVal.AddRange(_rels.Relations);
|
||||
|
||||
if (_rels.IsComplete)
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
return _retVal ;
|
||||
|
||||
if (RetVal2.Count > 0)
|
||||
return RetVal2;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
@@ -5589,7 +5554,7 @@ namespace C4IT.DataHistoryProvider
|
||||
if (infoClass == enumFasdInformationClass.Ticket)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.Ticket };
|
||||
if (infoClass == enumFasdInformationClass.VirtualSession)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.VirtualSession };
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, Instance = Identity.Instance, infoClass = enumFasdInformationClass.VirtualSession };
|
||||
if (infoClass == enumFasdInformationClass.MobileDevice)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.MobileDevice };
|
||||
|
||||
@@ -6911,6 +6876,8 @@ namespace C4IT.DataHistoryProvider
|
||||
|
||||
public enumFasdInformationClass infoClass { get; set; } = enumFasdInformationClass.Unknown;
|
||||
public Guid Id { get; set; }
|
||||
public Guid Instance { get; set; } = Guid.Empty;
|
||||
|
||||
public int? agentId { get; set; } = null;
|
||||
public int? agentId2 { get; set; } = null;
|
||||
public List<localIdEntry> localAgentIds { get; set; } = null;
|
||||
|
||||
@@ -42,40 +42,51 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
public const string constConnectorName = "Citrix Virtual Apps and Desktops connector";
|
||||
public const string constLicenseId = "F2DA5E05-FD3C-4182-9164-9C722140BF85";
|
||||
|
||||
public const string constCitrixUserList = "Users?$top={0}&$select=Id,Sid,Upn,Domain&$filter=Domain ne ''";
|
||||
public const string constCitrixSessionList = "Sessions?$expand=Machine($select=Id,DnsName,Name)&$select=SessionKey,StartDate,EndDate,ConnectionState";
|
||||
public const string constCitrixSessions = "Sessions?$filter=(EndDate eq null or EndDate gt {1}) and UserId in ({0})&$expand=Machine($select=Id,DnsName,Name)&$select=SessionKey,StartDate,EndDate,ConnectionState";
|
||||
public const string constCitrixSession = "Sessions?$filter=SessionKey eq {0}";
|
||||
public const string constCitrixSessionMetrics = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics";
|
||||
public const string constCitrixSessionMetricsIcaRTT = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,IcaRttMs)";
|
||||
public const string constCitrixSessionMetricsIcaLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,IcaLatency)";
|
||||
public const string constCitrixSessionMetricsClientL7Latency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,ClientL7Latency)";
|
||||
public const string constCitrixSessionMetricsServerL7Latency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,ServerL7Latency)";
|
||||
public const string constCitrixSessionMetricsInputBandwidthUsed = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,InputBandwidthUsed)";
|
||||
public const string constCitrixSessionMetricsOutputBandwidthUsed = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,OutputBandwidthUsed)";
|
||||
// urls for static tables
|
||||
public const string constCitrixSession = "Sessions?$filter=SessionKey eq {0}";
|
||||
public const string constCitrixSessionMachine = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=Machine($expand=CurrentLoadIndex,Catalog,DesktopGroup($select=Name)),Machine";
|
||||
public const string constCitrixSessionUser = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=User";
|
||||
public const string constCitrixSessionConnections = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=Connection";
|
||||
public const string constCitrixSessionCurrentConnection = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=CurrentConnection,LogOnMetrics";
|
||||
|
||||
// urls for historic tables
|
||||
public const string constCitrixSessionMetrics = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics";
|
||||
|
||||
|
||||
// urls for detail tables
|
||||
public const string constCitrixSessionMetricsIcaRTT = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,IcaRttMs)";
|
||||
public const string constCitrixSessionMetricsIcaLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,IcaLatency)";
|
||||
public const string constCitrixSessionMetricsClientL7Latency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,ClientL7Latency)";
|
||||
public const string constCitrixSessionMetricsServerL7Latency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,ServerL7Latency)";
|
||||
public const string constCitrixSessionMetricsInputBandwidthUsed = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,InputBandwidthUsed)";
|
||||
public const string constCitrixSessionMetricsOutputBandwidthUsed = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,OutputBandwidthUsed)";
|
||||
public const string constCitrixSessionMetricsOutputBandwidthAvailable = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,OutputBandwidthAvailable)";
|
||||
public const string constCitrixSessionMetricsFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,Fps)";
|
||||
public const string constCitrixSessionMetricsInputFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,InputFps)";
|
||||
public const string constCitrixSessionMetricsOutputFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,OutputFps)";
|
||||
public const string constCitrixSessionMetricsWanLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,WanLatency)";
|
||||
public const string constCitrixSessionMetricsDcLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,DcLatency)";
|
||||
public const string constCitrixSessionMachine = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=Machine($expand=CurrentLoadIndex,Catalog,DesktopGroup($select=Name)),Machine";
|
||||
public const string constCitrixSessionCurrentConnection = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=CurrentConnection,LogOnMetrics";
|
||||
public const string constCitrixSessionConnections = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=Connection";
|
||||
public const string constCitrixSessionLogInSummaries = "Sessions?$filter=UserId in ({0})$select=Id,StartDate&$expand=User($select=UserName),LogOnSummaries($select=LogOnDuration,AuthenticationDuration,BrokingDuration,ProfileLoadDuration,GpoProcessingDuration,InteractiveSessionDuration)";
|
||||
public const string constCitrixSessionLogInSummaries2 = "LogOnSummaries?$expand=Session($expand=User)&$filter=UserId eq {0}";
|
||||
public const string constCitrixUserConnections = "Sessions?$filter=UserId in ({0})&$expand=Connection";
|
||||
public const string constCitrixSessionUser = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=User";
|
||||
public const string constCitrixSessionMetricsFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,Fps)";
|
||||
public const string constCitrixSessionMetricsInputFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,InputFps)";
|
||||
public const string constCitrixSessionMetricsOutputFps = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,OutputFps)";
|
||||
public const string constCitrixSessionMetricsWanLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,WanLatency)";
|
||||
public const string constCitrixSessionMetricsDcLatency = "Sessions?$select=SessionKey&$filter=SessionKey eq {0}&$expand=SessionMetrics($select=Id,CollectedDate,DcLatency)";
|
||||
public const string constCitrixSessionLogInSummaries = "Sessions?$filter=UserId in ({0})$select=Id,StartDate&$expand=User($select=UserName),LogOnSummaries($select=LogOnDuration,AuthenticationDuration,BrokingDuration,ProfileLoadDuration,GpoProcessingDuration,InteractiveSessionDuration)";
|
||||
public const string constCitrixUserConnections = "Sessions?$filter=UserId in ({0})&$expand=Connection";
|
||||
public const string constCitrixSessionLogInSummaries2 = "LogOnSummaries?$expand=Session($expand=User)&$filter=UserId eq {0}";
|
||||
|
||||
public const string constCitrixSessionLogoff = "manage/Sessions/{0}/$logoff";
|
||||
public const string constCitrixSessionHide = "manage/Sessions/{0}/$hide";
|
||||
public const string constCitrixSessionSendMessage = "manage/Sessions/{0}/$sendMessage";
|
||||
|
||||
// static tables
|
||||
public const string constTableNameSessionDetails = "citrix-session-details";
|
||||
|
||||
public const string constTableNameSession = "citrix-session";
|
||||
public const string constTableNameSessionMachine = "citrix-session-machine";
|
||||
public const string constTableNameSessionUser = "citrix-session-user";
|
||||
public const string constTableNameSessionConnection = "citrix-session-connection";
|
||||
public const string constTableNameSessionCurrentConnection = "citrix-session-currentConnection";
|
||||
|
||||
// history tables
|
||||
public const string constTableNameSessionMetrics = "citrix-session-metrics";
|
||||
public const string constTableNameSessionStateMetrics = "citrix-connectionState-metrics";
|
||||
public const string constTableNameSessionUser = "citrix-session-user";
|
||||
|
||||
// detail tables
|
||||
public const string constTableNameSessionDetailsIcaRttMS = "citrix-session-details-icaRttMS";
|
||||
public const string constTableNameSessionDetailsIcaLatency = "citrix-session-details-icaLatency";
|
||||
public const string constTableNameSessionDetailsClientL7Latency = "citrix-session-details-clientL7Latency";
|
||||
@@ -378,10 +389,12 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
|
||||
try
|
||||
{
|
||||
Collector.DoProcessUiMessage(0, $"Validating Citrix connections...");
|
||||
|
||||
List<cDataHistoryCitrixSystem> _toRemove = new List<cDataHistoryCitrixSystem>();
|
||||
foreach (var _system in unauthorizedSystems)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $"Try logon to {_system.Name}...");
|
||||
Collector.DoProcessUiMessage(1, $"Try logon to {_system.Name}...");
|
||||
var _ok = false;
|
||||
var CitrixConn = await LogonToSystemAsync(_system, token);
|
||||
if (token.IsCancellationRequested)
|
||||
@@ -396,9 +409,9 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
_ok = true;
|
||||
}
|
||||
if (_ok)
|
||||
Collector.DoProcessUiMessage(2, $"Successfull logon to {_system.Name}.");
|
||||
Collector.DoProcessUiMessage(1, $"Successfull logon to {_system.Name}.");
|
||||
else
|
||||
Collector.DoProcessUiMessage(2, $"Could not logon to {_system.Name}.", LogLevels.Error);
|
||||
Collector.DoProcessUiMessage(1, $"Could not logon to {_system.Name}.", LogLevels.Error);
|
||||
}
|
||||
|
||||
foreach (var _system in _toRemove)
|
||||
@@ -413,34 +426,13 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
}
|
||||
finally
|
||||
{
|
||||
Collector.DoProcessUiMessage(0, $"Validating Citrix connections finished.");
|
||||
if (CM != null) LogMethodEnd(CM);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<cCitrixCommunicationSystem> GetConnection(Guid SiteId)
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
|
||||
try
|
||||
{
|
||||
if (cachedConnections.TryGetValue(SiteId, out var cachedConnection))
|
||||
return cachedConnection;
|
||||
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (CM != null) LogMethodEnd(CM);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<cCitrixCommunicationSystem> LogonCitrixTenantAsync(cDataHistoryCitrixCloudTenant Tenant, bool force = false)
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
@@ -481,65 +473,6 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
return true;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public async Task<bool> GetCitrixUsersAsync()
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
try
|
||||
{
|
||||
var strUrl = string.Format(constCitrixUserList, constCitrixUserPaging);
|
||||
|
||||
var systems = Collector.InfrastructureConfig.Citrix.Systems;
|
||||
if (systems is null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $" Could not logon to tenant - Tenant is null", LogLevels.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
var _retVal = true;
|
||||
foreach (var _system in systems)
|
||||
{
|
||||
if (!(_system is cDataHistoryCitrixCloudTenant Tenant))
|
||||
continue;
|
||||
|
||||
var CitrixConn = await GetCitrixCommunicationForSystemAsync(Tenant.TenantID, true);
|
||||
if (CitrixConn == null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $"error: could not logon to tenat {Tenant.Domain}", LogLevels.Error);
|
||||
_retVal = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var Result = await CitrixConn.Monitor.Request.RequestAsync(strUrl, eHttpMethod.get, null);
|
||||
if (Result != null)
|
||||
{
|
||||
var _props = Result.Result as JObject;
|
||||
if (_props != null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(3, $" properties of selected '{_props}' with {_props.Count} properties could be read.");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $" Could not get user list from tenant {Tenant.Domain}", LogLevels.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
return _retVal;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (CM != null) LogMethodEnd(CM);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private class ScanSessionEntryProcessor : ScanEntryProcessor
|
||||
{
|
||||
private cCitrixCommunicationMonitor _comm;
|
||||
@@ -599,6 +532,7 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
LastUsed = endDate,
|
||||
UsingLevel = _duration == 0 ? 1 : _duration,
|
||||
id = SessionId,
|
||||
Instance = instanceId,
|
||||
Status = enumF4sdSearchResultStatus.Active,
|
||||
Infos = Infos,
|
||||
Identities = new cF4sdIdentityList()
|
||||
@@ -679,90 +613,6 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
}
|
||||
|
||||
return _retVal;
|
||||
|
||||
string userIds = string.Join(",", UserIds.Where(u => !string.IsNullOrWhiteSpace(u?.citrixUserId.ToString())).Select(u => u.citrixUserId));
|
||||
|
||||
//DateTime latestEndDate = DateTime.UtcNow.AddDays(-age);
|
||||
//ToDo: originale Altersberechnung wiederherstellen
|
||||
DateTime latestEndDate = DateTime.UtcNow.AddDays(-90);
|
||||
var strUrl = string.Format(constCitrixSessions, userIds, latestEndDate.ToString("yyyy-MM-ddThh:mm:ssK"));
|
||||
|
||||
var tenantId = UserIds?.FirstOrDefault(u => !string.IsNullOrWhiteSpace(u?.citrixTenantId))?.citrixTenantId;
|
||||
if (tenantId is null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $" Could not logon to tenant - Tenant is null", LogLevels.Warning);
|
||||
return null;
|
||||
}
|
||||
|
||||
var CitrixConn = await GetCitrixCommunicationForSystemAsync(tenantId, true);
|
||||
|
||||
if (CitrixConn == null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $"error: could not logon to tenat {tenantId}", LogLevels.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
// ToDo: Implement a paged walkthrough of results in case there are more results than the API can return in one call
|
||||
// maybe we should think about a concrete implementation of the results instead of a dynamic, what do you think?
|
||||
var Result = await CitrixConn.Monitor.Request.RequestListAsync(strUrl, false, retryForbidden: false);
|
||||
|
||||
if (Result != null && Result.Count > 0)
|
||||
{
|
||||
var sessionResult = new List<cF4sdApiSearchResultRelation>(Result.Count);
|
||||
double _sumDuration = 0;
|
||||
foreach (var Entry in Result)
|
||||
{
|
||||
var endDate = DateTime.MinValue;
|
||||
if (!DateTime.TryParse(Entry.Result.EndDate?.ToString(), out endDate))
|
||||
endDate = DateTime.UtcNow;
|
||||
|
||||
var startDate = DateTime.MinValue;
|
||||
if (!DateTime.TryParse(Entry.Result.StartDate?.ToString(), out startDate))
|
||||
startDate = DateTime.UtcNow;
|
||||
|
||||
TimeSpan _duration = endDate - startDate;
|
||||
_sumDuration += _duration.TotalSeconds;
|
||||
|
||||
Enum.TryParse(Entry.Result.ConnectionState.ToString(), out enumCitrixSessionStatus connectionState);
|
||||
|
||||
var Infos = new Dictionary<string, string>()
|
||||
{
|
||||
|
||||
{ "Status",connectionState.ToString() },
|
||||
{ "StatusId", Entry.Result.ConnectionState.ToString() },
|
||||
{ "Domain", Regex.Replace(Entry.Result.Machine.Name?.ToString(), @"\\.*$", "") }
|
||||
};
|
||||
var sessionInfo = new cF4sdApiSearchResultRelation()
|
||||
{
|
||||
Type = enumF4sdSearchResultClass.VirtualSession,
|
||||
Name = Regex.Replace(Entry.Result.Machine.Name.ToString(), @"^.*\\", ""),
|
||||
DisplayName = Regex.Replace(Entry.Result.Machine.Name.ToString(), @"^.*\\", ""),
|
||||
LastUsed = endDate,
|
||||
// minor thing due to the fact we did it like that in the Agent before, but:
|
||||
// Instead of setting the UsingLevel to a temporary value and calculate the actual value later,
|
||||
// we should maybe calculate the sumvalue beforehand and apply only the calculation here, what do you think?
|
||||
UsingLevel = _duration.TotalSeconds == 0 ? 1 : _duration.TotalSeconds,
|
||||
id = Entry.Result.SessionKey,
|
||||
Status = enumF4sdSearchResultStatus.Active,
|
||||
Infos = Infos,
|
||||
Identities = new cF4sdIdentityList()
|
||||
{
|
||||
new cF4sdIdentityEntry(){ Class = enumFasdInformationClass.User, Id = UserIds.First().Id},
|
||||
new cF4sdIdentityEntry(){ Class = enumFasdInformationClass.VirtualSession, Id = Entry.Result.SessionKey}
|
||||
}
|
||||
};
|
||||
sessionResult.Add(sessionInfo);
|
||||
}
|
||||
if (sessionResult != null && sessionResult.Count > 0)
|
||||
{
|
||||
foreach (var Entry in sessionResult)
|
||||
{
|
||||
Entry.UsingLevel /= _sumDuration;
|
||||
}
|
||||
}
|
||||
return sessionResult;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
@@ -919,179 +769,6 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<cF4SDHealthCardRawData.cHealthCardTable>> GetSessionStateMetricsAsync(cF4sdConnectorIds UserIds, string TenantId, cF4sdWebRequestInfo RequestInfo, int MaxAge, int LogDeep, CancellationToken Token)
|
||||
{
|
||||
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
if (cPerformanceLogger.IsActive && RequestInfo != null) { if (CM == null) CM = MethodBase.GetCurrentMethod(); cPerformanceLogger.LogPerformanceStart(LogDeep, CM, RequestInfo.id, RequestInfo.created); }
|
||||
var _startTime = DateTime.UtcNow;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var strUrl = string.Format(constCitrixSessions, UserIds.citrixUserId.ToString());
|
||||
|
||||
if (!Collector.ClusterConfig.Tables.TryGetValue(constTableNameSessionStateMetrics, out var SessionTableDetails))
|
||||
return null;
|
||||
|
||||
var citrixCommunication = await GetCitrixCommunicationForSystemAsync(TenantId, true);
|
||||
if (citrixCommunication == null)
|
||||
return null;
|
||||
|
||||
var res = await citrixCommunication.Monitor.Request.RequestAsync(strUrl, eHttpMethod.get, null);
|
||||
if (res != null)
|
||||
{
|
||||
JObject sessionInfos = res.Result;
|
||||
var retVal = new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
{
|
||||
Name = constTableNameSessionStateMetrics,
|
||||
InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
IsStatic = true,
|
||||
TableType = eDataHistoryTableType.Static
|
||||
};
|
||||
|
||||
var dicVals = new List<Dictionary<string, object>>();
|
||||
var vals = sessionInfos.Children();
|
||||
var metricsObj = sessionInfos["value"] as JArray;
|
||||
|
||||
if (metricsObj != null)
|
||||
{
|
||||
dicVals = metricsObj
|
||||
.OfType<JObject>()
|
||||
.Where(o =>
|
||||
o["StartDate"] != null &&
|
||||
o["ConnectionState"] != null &&
|
||||
DateTime.TryParse(o["StartDate"].ToString(), out _)
|
||||
)
|
||||
.GroupBy(o => new
|
||||
{
|
||||
Date = DateTime.Parse(o["StartDate"].ToString()).Date,
|
||||
ConnectionState = (int)o["ConnectionState"]
|
||||
})
|
||||
.OrderBy(g => g.Key.Date)
|
||||
.Select(g => new Dictionary<string, object>
|
||||
{
|
||||
{ "StartDate", g.Key.Date }, // ✅ DateTime
|
||||
{ "ConnectionState", g.Key.ConnectionState },
|
||||
{ "ConnectionCount", g.Count() }
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
|
||||
const string startDateColumnName = "StartDate";
|
||||
const string connectionStatusColumnName = "ConnectionState";
|
||||
|
||||
var groupedValues = dicVals
|
||||
.Where(v =>
|
||||
v.TryGetValue(startDateColumnName, out var collectDate) &&
|
||||
collectDate is DateTime &&
|
||||
v.TryGetValue(connectionStatusColumnName, out _))
|
||||
.GroupBy(v => new
|
||||
{
|
||||
StartDate = ((DateTime)v[startDateColumnName]).Date,
|
||||
ConnectionStatus = v[connectionStatusColumnName]
|
||||
})
|
||||
.Select(g => new Dictionary<string, object>
|
||||
{
|
||||
{ startDateColumnName, g.Key.StartDate },
|
||||
{ connectionStatusColumnName, g.Key.ConnectionStatus },
|
||||
{ "ConnectionCount", g.Count() }
|
||||
})
|
||||
.ToLookup(d => new
|
||||
{
|
||||
StartDate = (DateTime)d[startDateColumnName],
|
||||
ConnectionStatus = d[connectionStatusColumnName],
|
||||
ConnectionCount = d["ConnectionCount"]
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < MaxAge; i++)
|
||||
{
|
||||
DateTime referenceDate = DateTime.Now.AddDays(-i).Date;
|
||||
|
||||
//var valuesOfDay = groupedValues.FirstOrDefault(v => v.Key.Date == referenceDate);
|
||||
var valuesOfDay = groupedValues.Where(g => g.Key.StartDate == referenceDate).SelectMany(g => g).ToList();
|
||||
|
||||
foreach (var colInfo in SessionTableDetails.Columns.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valuesOfDay is null)
|
||||
{
|
||||
AddColumnData(retVal, colInfo.SourceName, ConvertToF4sdType(null, colInfo.ValueType));
|
||||
continue;
|
||||
}
|
||||
|
||||
var valuesOfColumn = valuesOfDay
|
||||
.Select(v =>
|
||||
{
|
||||
if (v.TryGetValue(colInfo.SourceName, out var colValue))
|
||||
return colValue;
|
||||
else
|
||||
return null;
|
||||
})
|
||||
.Where(v => v != null);
|
||||
|
||||
if (!valuesOfColumn.Any())
|
||||
{
|
||||
AddColumnData(retVal, colInfo.SourceName, ConvertToF4sdType(null, colInfo.ValueType));
|
||||
continue;
|
||||
}
|
||||
if (colInfo is cDataHistoryConfigColumn configColumn && configColumn.AggregationType != eDataHistoryAggregationType.Unknown)
|
||||
{
|
||||
var aggregatedValue = GetAggregationValue(valuesOfColumn, configColumn.AggregationType, colInfo.ValueType);
|
||||
AddColumnData(retVal, colInfo.SourceName, ConvertToF4sdType(aggregatedValue, colInfo.ValueType));
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = valuesOfColumn.FirstOrDefault();
|
||||
AddColumnData(retVal, colInfo.SourceName, ConvertToF4sdType(value, colInfo.ValueType));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new List<cF4SDHealthCardRawData.cHealthCardTable>(1) { retVal };
|
||||
}
|
||||
else
|
||||
{
|
||||
LogEntry($"Could not get detailed sessionmetrics information from citrix with id {UserIds}. Sessionmetrics content is empty.", LogLevels.Warning);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (cPerformanceLogger.IsActive && RequestInfo != null) { cPerformanceLogger.LogPerformanceEnd(LogDeep, CM, RequestInfo.id, RequestInfo.created, _startTime); }
|
||||
if (CM != null) LogMethodEnd(CM);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
void AddColumnData(cF4SDHealthCardRawData.cHealthCardTable table, string columnName, object value)
|
||||
{
|
||||
if (table.Columns.TryGetValue(columnName, out var columnValues))
|
||||
columnValues.Values.Add(value);
|
||||
else
|
||||
table.Columns.Add(columnName, new cF4SDHealthCardRawData.cHealthCardTableColumn(table) { ColumnName = columnName, Values = new List<object>() { value } });
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<cF4SDHealthCardRawData.cHealthCardDetailsTable>> GetSessionMetricsDetailsIcaRttMSAsync(Guid Sessionid, string TenantId, cF4sdWebRequestInfo RequestInfo, int MaxAge, DateTime RefTime, int LogDeep, CancellationToken Token)
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
@@ -3038,6 +2715,127 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
|
||||
}
|
||||
|
||||
private class RequestFieldList
|
||||
{
|
||||
internal Dictionary<string, string> fields = new Dictionary<string, string>();
|
||||
internal Dictionary<string, RequestFieldList> SubNodes = new Dictionary<string, RequestFieldList>();
|
||||
}
|
||||
|
||||
private void addRequestField(RequestFieldList list, string fieldPath, string fieldName)
|
||||
{
|
||||
var arrItems = fieldPath.Split('.');
|
||||
if (arrItems.Length == 1)
|
||||
list.fields[arrItems[0]] = fieldName;
|
||||
else if (arrItems.Length > 1)
|
||||
{
|
||||
var _node = arrItems[0];
|
||||
var _newPath = fieldPath.Remove(0, _node.Length + 1);
|
||||
if (!list.SubNodes.TryGetValue(_node, out var _newList))
|
||||
{
|
||||
_newList = new RequestFieldList();
|
||||
list.SubNodes.Add(_node, _newList);
|
||||
}
|
||||
|
||||
addRequestField(_newList, _newPath, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
private RequestFieldList getRequestFieldList(cDataHistoryConfigTable table)
|
||||
{
|
||||
try
|
||||
{
|
||||
var _result = new RequestFieldList();
|
||||
|
||||
foreach (var _colum in table.Columns.Values)
|
||||
addRequestField(_result, _colum.SourceName, _colum.Name);
|
||||
|
||||
return _result;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private string getUrlSelectionSubFields(string name, RequestFieldList list)
|
||||
{
|
||||
var _select = string.Empty;
|
||||
foreach (var _entry in list.fields)
|
||||
{
|
||||
if (_select != string.Empty)
|
||||
_select += ",";
|
||||
_select += _entry.Key;
|
||||
}
|
||||
|
||||
var _expand = string.Empty;
|
||||
foreach (var _entry in list.SubNodes)
|
||||
{
|
||||
var _sub = getUrlSelectionSubFields(_entry.Key, _entry.Value);
|
||||
if (!string.IsNullOrEmpty(_sub))
|
||||
{
|
||||
if (_expand != string.Empty)
|
||||
_expand += ",";
|
||||
_expand += _sub;
|
||||
}
|
||||
}
|
||||
|
||||
var _retVal = string.Empty;
|
||||
if (_select != string.Empty)
|
||||
_retVal = name + "($select=" + _select + ")";
|
||||
|
||||
if (_expand != string.Empty)
|
||||
{
|
||||
if (_retVal != string.Empty)
|
||||
_retVal += ",";
|
||||
_retVal += name + "($expand=" + _expand + ")";
|
||||
}
|
||||
|
||||
return _retVal;
|
||||
}
|
||||
|
||||
private string getUrlSelection(RequestFieldList list)
|
||||
{
|
||||
try
|
||||
{
|
||||
var _select = string.Empty;
|
||||
foreach (var _entry in list.fields)
|
||||
{
|
||||
if (_entry.Key == "SiteId" || _entry.Key == "SiteName")
|
||||
continue;
|
||||
if (_select != string.Empty)
|
||||
_select += ",";
|
||||
_select += _entry.Key;
|
||||
}
|
||||
|
||||
var _expand = string.Empty;
|
||||
foreach (var _entry in list.SubNodes)
|
||||
{
|
||||
var _sub = getUrlSelectionSubFields(_entry.Key, _entry.Value);
|
||||
if (!string.IsNullOrEmpty(_sub))
|
||||
{
|
||||
if (_expand != string.Empty)
|
||||
_expand += ",";
|
||||
_expand += _sub;
|
||||
}
|
||||
}
|
||||
|
||||
var _result = string.Empty;
|
||||
if (_select != string.Empty)
|
||||
_result = "&$select=" + _select;
|
||||
|
||||
if (_expand != string.Empty)
|
||||
_result += "&$expand=" + _expand;
|
||||
|
||||
return _result;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override async Task<List<cF4SDHealthCardRawData.cHealthCardTable>> GetTableResultsVirtualAsync(List<cDataHistoryConfigTable> Tables, Dictionary<enumFasdInformationClass, cF4sdConnectorIds> Identities, DateTime RefTime, int MaxAge, bool instantly, Guid? CacheId, CancellationToken Token, cF4sdWebRequestInfo requestInfo, int LogDeep)
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
@@ -3049,118 +2847,78 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
if (!Identities.TryGetValue(enumFasdInformationClass.VirtualSession, out var session) || session?.Id is null)
|
||||
return null;
|
||||
|
||||
if (!Identities.TryGetValue(enumFasdInformationClass.User, out var userIds) || userIds?.citrixTenantId is null)
|
||||
var _instance = session.Instance;
|
||||
if (_instance == null)
|
||||
return null;
|
||||
|
||||
var citrixTableNames = new HashSet<string>(Tables.Where(t => t?.ParentCluster?.Origin == enumDataHistoryOrigin.Citrix).Select(t => t.Name), StringComparer.Ordinal);
|
||||
|
||||
bool Has(string tableName) => tableName != null && citrixTableNames.Contains(tableName);
|
||||
|
||||
var _userExists = Has(constTableNameSessionUser);
|
||||
var _sessionExists = Has(constTableNameSession);
|
||||
var _machineExists = Has(constTableNameSessionMachine);
|
||||
var _connectionExists = Has(constTableNameSessionConnection);
|
||||
var _currentConnectionExists = Has(constTableNameSessionCurrentConnection);
|
||||
var _sessionMetricsExists = Has(constTableNameSessionMetrics);
|
||||
|
||||
var retVal = new List<cF4SDHealthCardRawData.cHealthCardTable>();
|
||||
var listTasks = new List<Task<List<cF4SDHealthCardRawData.cHealthCardTable>>>(2);
|
||||
|
||||
if (_sessionExists)
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSession,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
if (_sessionMetricsExists)
|
||||
var _detailTable = Tables.Where(_t => _t.Name == constTableNameSessionDetails).First();
|
||||
if (_detailTable == null)
|
||||
{
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSessionMetrics,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
// ToDo: create an empty table
|
||||
}
|
||||
else
|
||||
{
|
||||
var _fieldList = getRequestFieldList(_detailTable);
|
||||
var _select = getUrlSelection(_fieldList);
|
||||
|
||||
var _url = string.Format(constCitrixSession, session.Id.ToString("D")) + _select;
|
||||
|
||||
await ValidateConnectionsAsync(Token);
|
||||
if (Token.IsCancellationRequested) return null;
|
||||
|
||||
if (!cachedConnections.TryGetValue(_instance, out var _conn))
|
||||
return null;
|
||||
|
||||
var _sessionData = await _conn.Monitor.Request.RequestAsync(_url, eHttpMethod.get, null, token: Token);
|
||||
if (Token.IsCancellationRequested) return null;
|
||||
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionMetricsAsync(session.Id, userIds.citrixTenantId, requestInfo, MaxAge, LogDeep + 1, Token); }));
|
||||
//listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionStateMetricsAsync(userIds, userIds.citrixTenantId, requestInfo, MaxAge, LogDeep + 1, Token); }));
|
||||
}
|
||||
|
||||
|
||||
if (_machineExists)
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSessionMachine,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionMachineAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
return null;
|
||||
|
||||
if (_connectionExists)
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSessionConnection,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionConnectionsAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
//var citrixTableNames = new HashSet<string>(Tables.Where(t => t?.ParentCluster?.Origin == enumDataHistoryOrigin.Citrix).Select(t => t.Name), StringComparer.Ordinal);
|
||||
//bool Has(string tableName) => tableName != null && citrixTableNames.Contains(tableName);
|
||||
|
||||
if (_currentConnectionExists)
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSessionCurrentConnection,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionCurrentConnectionAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
//var _userExists = Has(constTableNameSessionUser);
|
||||
//var _sessionExists = Has(constTableNameSession);
|
||||
//var _machineExists = Has(constTableNameSessionMachine);
|
||||
//var _connectionExists = Has(constTableNameSessionConnection);
|
||||
//var _currentConnectionExists = Has(constTableNameSessionCurrentConnection);
|
||||
//var _sessionMetricsExists = Has(constTableNameSessionMetrics);
|
||||
|
||||
if (_userExists)
|
||||
//if (CacheId == null && !instantly)
|
||||
//{
|
||||
// retVal.Add(new cF4SDHealthCardRawData.cHealthCardTable()
|
||||
// {
|
||||
// Name = constTableNameSessionUser,
|
||||
// InformationClass = enumFasdInformationClass.VirtualSession,
|
||||
// IsIncomplete = true
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionUserAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
//var retVal = new List<cF4SDHealthCardRawData.cHealthCardTable>();
|
||||
//var listTasks = new List<Task<List<cF4SDHealthCardRawData.cHealthCardTable>>>(2);
|
||||
|
||||
//if (_sessionExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
//if (_sessionMetricsExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionMetricsAsync(session.Id, userIds.citrixTenantId, requestInfo, MaxAge, LogDeep + 1, Token); }));
|
||||
|
||||
//if (_machineExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionMachineAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
//if (_connectionExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionConnectionsAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
//if (_currentConnectionExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionCurrentConnectionAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
//if (_userExists)
|
||||
// listTasks.Add(Task.Run<List<cF4SDHealthCardRawData.cHealthCardTable>>(async () => { return await GetSessionUserAsync(session.Id, userIds.citrixTenantId, requestInfo, LogDeep + 1, Token); }));
|
||||
|
||||
|
||||
var arrRes = await Task.WhenAll(listTasks.ToArray());
|
||||
foreach (var Entry in arrRes)
|
||||
if (Entry != null)
|
||||
retVal.AddRange(Entry);
|
||||
//var arrRes = await Task.WhenAll(listTasks.ToArray());
|
||||
//foreach (var Entry in arrRes)
|
||||
// if (Entry != null)
|
||||
// retVal.AddRange(Entry);
|
||||
|
||||
|
||||
if (retVal.Count == 0)
|
||||
return null;
|
||||
//if (retVal.Count == 0)
|
||||
// return null;
|
||||
|
||||
return retVal;
|
||||
//return retVal;
|
||||
|
||||
}
|
||||
catch (Exception E)
|
||||
@@ -3176,56 +2934,6 @@ namespace C4IT.DataHistoryProvider.Base.Modules.Citrix
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> GetCitrixSessionsAsync()
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
try
|
||||
{
|
||||
var strUrl = string.Format(constCitrixSessionList, constCitrixUserPaging);
|
||||
|
||||
var systems = Collector.InfrastructureConfig.Citrix.Systems;
|
||||
if (systems is null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $" Could not logon to tenant - Tenant is null", LogLevels.Warning);
|
||||
return false;
|
||||
}
|
||||
foreach (var _system in systems)
|
||||
{
|
||||
if (!(_system is cDataHistoryCitrixCloudTenant Tenant))
|
||||
continue;
|
||||
|
||||
var CitrixConn = await GetCitrixCommunicationForSystemAsync(Tenant.TenantID, true);
|
||||
if (CitrixConn == null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(2, $"error: could not logon to tenat {Tenant.Domain}", LogLevels.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
var Result = await CitrixConn.Monitor.Request.RequestAsync(strUrl, eHttpMethod.get, null);
|
||||
if (Result != null)
|
||||
{
|
||||
var _ty = Result.GetType();
|
||||
var _props = Result.Result as JObject;
|
||||
if (_props != null)
|
||||
{
|
||||
Collector.DoProcessUiMessage(3, $" properties of selected '{_props}' with {_props.Count} properties could be read.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (CM != null) LogMethodEnd(CM);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async override Task<bool> DoScanAsync(bool Always, bool Rescan, cF4sdWebRequestInfo requestInfo, int LogDeep, CancellationToken Token, bool EnhancedDebug = false)
|
||||
{
|
||||
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
|
||||
|
||||
Reference in New Issue
Block a user