public void Execute() { try { var qmsAddress = Settings.GetSetting($"{MonitorName}.QmsAddress", "(undefined)"); DirectorySetting archivedLogsLocation; if (qmsAddress.Equals("(undefined)", StringComparison.InvariantCultureIgnoreCase)) { qmsAddress = $"http://{(Dns.GetHostEntry(Dns.GetHostName()).HostName).ToLower()}:4799/QMS/Service"; } string installationId; License licence = null; using (var qmsApiService = new QMS_API.AgentsQmsApiService(qmsAddress)) { if (!qmsApiService.TestConnection()) { Log.To.Main.Add($"Could not connect to QMS API {qmsAddress} in {MonitorName}"); return; } List <ServiceInfo> qvsServices = qmsApiService.GetServices(ServiceTypes.QlikViewServer); QVSSettings qvsSettings = qmsApiService.GetQvsSettings(qvsServices[0].ID, QVSSettingsScope.Logging); var folder = qvsSettings.Logging.Folder; if (!Directory.Exists(folder)) { Log.To.Main.Add($"The folder does not exist or we don't have access to the folder:'{folder}' will not read logs."); return; } archivedLogsLocation = new DirectorySetting(folder); var services = qmsApiService.GetServices(ServiceTypes.QlikViewServer | ServiceTypes.QlikViewDistributionService); var qvServers = services.Where(p => p.Type == ServiceTypes.QlikViewServer).ToList(); installationId = qvServers.OrderBy(p => p.ID).First().ID.ToString(); qvServers.ForEach(p => { licence = qmsApiService.GetLicense(p.Type == ServiceTypes.QlikViewServer ? LicenseType.QlikViewServer : LicenseType.Publisher, p.ID); }); } var logMinerData = new FileMinerDto(); var data = new StatisticsDto { LogFileMinerData = logMinerData, CollectionDateUtc = logMinerData.CollectionDateUtc }; var settings = new LogFileDirectorSettings { StartDateForLogs = DateTime.Now.AddDays(-2).Date, StopDateForLogs = DateTime.Now.AddDays(-1).Date.AddMilliseconds(-1), }; //settings.StartDateForLogs = DateTime.Parse("2019-04-30 00:00:00").AddDays(FAKERUNCOUNT); //settings.StopDateForLogs = DateTime.Parse("2019-04-30 23:59:59").AddDays(FAKERUNCOUNT); //archivedLogsLocation = new DirectorySetting(@"C:\ProgramData\QlikTech\QlikViewServer"); var logFileDirector = new QvLogDirector(); data.InstallationId = $"{licence?.Serial ?? "(unknown)"}_{installationId} "; data.QlikViewLicence = _licenceHelper.AnalyzeLicense(licence); data.LogFileMinerData.LicenseSerialNo = licence?.Serial ?? "(unknown qv)"; Log.To.Main.Add($"Starting log director on {archivedLogsLocation.Path}"); logFileDirector.LoadAndRead(archivedLogsLocation, settings, logMinerData); Notify($"{MonitorName} has analyzed the following system", new List <string> { JsonConvert.SerializeObject(data, Formatting.Indented) }, "-1"); FAKERUNCOUNT++; } catch (Exception ex) { Log.To.Main.AddException($"Failed executing {MonitorName}", ex); } }
public void CollectFromApi() { try { var collectionStatus = MessageLevels.Ok; _notify("Starting Collecting from API", MessageLevels.Animate, "ApiCollector"); using (var qmsApiService = new QMS_API.AgentsQmsApiService(_settings.QvSettings.QmsAddress)) { if (!qmsApiService.TestConnection()) { _logger.Add("Could not connect to QMS API (" + _settings.QvSettings.QmsAddress + ")!"); _notify("Failed Collecting from API", MessageLevels.Error, "ApiCollector"); return; } var services = qmsApiService.GetServices(); List <Guid> serviceIDs = services.Select(t => t.ID).ToList(); //List<ServiceInfo> qvsServices = qmsApiService.GetServices(ServiceTypes.QlikViewServer); _collectorHelper.WriteContentToFile(qmsApiService.GetServiceStatuses(serviceIDs), "QvServiceStatuses"); _collectorHelper.WriteContentToFile(services, "QvServices"); var qvServers = services.Where(p => p.Type == ServiceTypes.QlikViewServer | p.Type == ServiceTypes.QlikViewDistributionService).ToList(); _notify("Collecting Service info from API", MessageLevels.Animate, "ApiCollector"); qvServers.ForEach(p => { if (p.Type == ServiceTypes.QlikViewServer) { QVSSettings settings = null; try { settings = qmsApiService.GetQvsSettings(p.ID, QVSSettingsScope.All); _collectorHelper.WriteContentToFile(settings, $"QvsSettings_{p.Name}"); _collectorHelper.WriteContentToFile(qmsApiService.GetCalConfiguration(p.ID, CALConfigurationScope.All), $"QvsCals_{p.Name}"); _collectorHelper.WriteContentToFile(qmsApiService.GetUserDocuments(p.ID), $"QvsUserDocuments_{p.Name}"); _collectorHelper.WriteContentToFile(qmsApiService.GetQvsDocumentsAndUsers(p.ID, QueryTarget.Resource), $"QvsDocumentsAndUsers_{p.Name}"); } catch (Exception e) { _logger.Add($"Failed collecting API details from {p.Name ?? "UndefinedService"}", e); _notify($"Failed collecting details from {p.Name}", MessageLevels.Warning, "ApiCollector"); collectionStatus = MessageLevels.Warning; } _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"Qvs settings - {p.Name}", Type = QvLogLocationSource.QvsSetting, Path = settings?.Logging?.Folder ?? "Failed retrival" }); _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"Qvs Root Folder - {p.Name}", Type = QvLogLocationSource.QvsSetting, Path = settings?.Folders?.UserDocumentRootFolder ?? "Failed retrival" }); } if (p.Type == ServiceTypes.QlikViewDistributionService) { var docs = GetAllDocumentsAndFolders(qmsApiService, p); _collectorHelper.WriteContentToFile(docs, $"QvsDocumentsAndFolders_{p.Name}"); var qdsSettings = qmsApiService.GetQdsSettings(p.ID, QDSSettingsScope.All); qdsSettings.General.ClusterInfo.ForEach(clusterInfo => { var hostName = clusterInfo.Url.Host; _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"Programdata - QlikTech - {hostName}", Type = QvLogLocationSource.QdsClusterInfoUrl, Path = $"\\\\{hostName}\\c$\\ProgramData\\QlikTech" }); _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"ProgramFiles - QlikView - {hostName}", Type = QvLogLocationSource.QdsClusterInfoUrl, Path = $"\\\\{hostName}\\c$\\Program Files\\QlikView", LogCollectionType = QvLogCollectionType.SettingsOnly }); _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"CommonFiles - QlikTech - {hostName}", Type = QvLogLocationSource.QdsClusterInfoUrl, Path = $"\\\\{hostName}\\c$\\Program Files\\Common Files\\QlikTech", LogCollectionType = QvLogCollectionType.SettingsOnly }); }); _settings.QvSettings.QvLogLocations.Add(new QvLogLocation { Name = $"QDS Application DataFolder - {p.Name}", Type = QvLogLocationSource.QdsSettingsApplicationDataFolder, Path = qdsSettings.General.ApplicationDataFolder, IgnorePaths = IgnoreQdsApplicationDataFolder, LogCollectionType = QvLogCollectionType.SettingsOnly }); _collectorHelper.WriteContentToFile(qdsSettings, $"QdsSettings_{p.Name}"); } _collectorHelper.WriteContentToFile(qmsApiService.GetLicense(p.Type == ServiceTypes.QlikViewServer ? LicenseType.QlikViewServer : LicenseType.Publisher, p.ID), $"License_{p.Name}"); }); if (collectionStatus == MessageLevels.Ok) { _notify("Finished collectinging from API", MessageLevels.Ok, "ApiCollector"); } else { _notify("Finished collectinging from API but some errors where found.", MessageLevels.Warning, "ApiCollector"); } //Analyze(qmsApiService); } } catch (Exception e) { _logger.Add("Failed collecting from API", e); _notify("Failed collecting from API", MessageLevels.Error, "ApiCollector"); } }
public void Execute() { try { var data = new StatisticsDto(); var cals = new List <QvCalAgentDto>(); var qmsAddress = Settings.GetSetting($"{MonitorName}.QmsAddress", "(undefined)"); if (qmsAddress.Equals("(undefined)", StringComparison.InvariantCultureIgnoreCase)) { qmsAddress = $"http://{(Dns.GetHostEntry(Dns.GetHostName()).HostName).ToLower()}:4799/QMS/Service"; } WmiSystemInfoDto wmiData = new WmiSystemInfoDto(); var exceptionList = new List <Exception>(); try { wmiData = new WmiSystemInfo().GetValuesFromWin32Os(); } catch (Exception e) { data.Exceptions.Add(e); } using (var qmsApiService = new QMS_API.AgentsQmsApiService(qmsAddress)) { if (!qmsApiService.TestConnection()) { Log.To.Main.Add($"Could not connect to QMS API ({qmsAddress})!"); return; } var services = qmsApiService.GetServices(ServiceTypes.QlikViewServer | ServiceTypes.QlikViewDistributionService); var qvServers = services.Where(p => p.Type == ServiceTypes.QlikViewServer).ToList(); var installationId = qvServers.OrderBy(p => p.ID).First().ID.ToString(); qvServers.ForEach(p => { if (p.Type == ServiceTypes.QlikViewServer) { var calConfigurations = new[] { qmsApiService.GetCalConfiguration(p.ID, CALConfigurationScope.DocumentCALs), qmsApiService.GetCalConfiguration(p.ID, CALConfigurationScope.NamedCALs), qmsApiService.GetCalConfiguration(p.ID, CALConfigurationScope.SessionCALs), qmsApiService.GetCalConfiguration(p.ID, CALConfigurationScope.UsageCALs) }; cals.Add(_licenceHelper.ComputeCals(p, calConfigurations)); } var license = qmsApiService.GetLicense(p.Type == ServiceTypes.QlikViewServer ? LicenseType.QlikViewServer : LicenseType.Publisher, p.ID); data.InstallationId = $"{license?.Serial ?? "(unknown)"}_{installationId} "; data.WmiSystemInfo = wmiData; data.QlikViewLicence = _licenceHelper.AnalyzeLicense(license); data.QlikViewCals = cals; data.Exceptions = exceptionList; Notify($"{MonitorName} has analyzed the following system", new List <string> { JsonConvert.SerializeObject(data, Formatting.Indented) }, "-1"); }); } } catch (Exception ex) { Log.To.Main.AddException($"Failed executing {MonitorName}", ex); } }