Ejemplo n.º 1
0
 public ApiCollector(ILogger logger, Action <string, MessageLevels, string> notify, CommonCollectorServiceVariables settings)
 {
     _logger          = logger;
     _collectorHelper = new CollectorHelper(settings, _logger);
     _notify          = notify;
     _settings        = settings;
 }
        public Task ReadArchivedLogs(string archivedLogsLocation, CommonCollectorServiceVariables settings)
        {
            _logger.Add("Reading Archived Logs");
            var a = new StreamLogDirector(_logger, _notify)
            {
                FriendlyName = "Archived Logs", NotificationKey = "ArchivedLogs"
            };

            return(Task.Run(async() =>
            {
                //a.OnLogDirectorFinishedReading(_onFinished);
                if (string.IsNullOrEmpty(archivedLogsLocation))
                {
                    archivedLogsLocation = $@"\\{settings.DnsHostName}\SenseShare\Archived Logs";
                }
                //todo: warning fix this.....
                _logger.Add($"Started reading Archived Logs at {archivedLogsLocation}");
                a.LoadAndRead(new[] { new DirectorySetting(archivedLogsLocation) }, settings);
                TotalNumberOfLogFiles += a.FoundFileCount;
                _logger.Add($"Started reading NPrinting logs locally at c:");
                await new NPrintingCollector(FileSystem.Singleton, _logger).GetLogs(@"c:\", settings, FileSystem.Singleton.Path.Combine(settings.OutputFolderPath, settings.DnsHostName)).ConfigureAwait(false);
                _logger.Add($"Started reading Connectors logs locally at c:");
                await new ConnectorsLogCollector(FileSystem.Singleton, _logger).GetLogs(@"c:\", settings, FileSystem.Singleton.Path.Combine(settings.OutputFolderPath, settings.DnsHostName)).ConfigureAwait(false);
                _logger.Add($"Finished reading archived and local logs");
            }
                            ).ContinueWith(p =>
            {
                _onFinished.Invoke(a);
            }));
        }
Ejemplo n.º 3
0
 public async Task <bool> Start(CommonCollectorServiceVariables settings)
 {
     ServiceVariables = settings;
     _collectorHelper = new CollectorHelper(settings, _logger);
     ValidateFuncs();
     return(await RunCollectionFlow().ConfigureAwait(false));
 }
        /// <summary>
        /// This is used by Product Support for being able to embedd variables for the executable in the filename.
        /// This enables them to send generic exe that contains case number and dates needed for the tool.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public CommonCollectorServiceVariables DecodeFileName(string filename)
        {
            var ret = new CommonCollectorServiceVariables();

            if (filename.Length < 17 || !filename.Contains("_"))
            {
                return(ret);
            }
            if (filename.Substring(filename.Length - 4, 1) == ".")
            {
                filename = Path.GetFileNameWithoutExtension(filename);
            }

            var filepart    = filename.Substring(16);
            var valueString = _encoder.Decode(filepart).ToString();

            ret.StartDateForLogs = DateTime.ParseExact(valueString.Substring(0, 6), "yyMMdd", CultureInfo.InvariantCulture);
            ret.StopDateForLogs  = DateTime.ParseExact(valueString.Substring(6, 6), "yyMMdd", CultureInfo.InvariantCulture);
            SenseCollectorVariableTypes flags;

            Enum.TryParse(valueString.Substring(12, 3), out flags);
            ret.Key = valueString.Substring(15);
            ret.AllowWindowsLogs  = flags.HasFlag(SenseCollectorVariableTypes.AllowWindowsLogs);
            ret.AllowMachineInfo  = flags.HasFlag(SenseCollectorVariableTypes.AllowMachineInfo);
            ret.UseOnlineDelivery = flags.HasFlag(SenseCollectorVariableTypes.UseOnlineDelivery);
            ret.GetLogsMain       = flags.HasFlag(SenseCollectorVariableTypes.MainLogs);
            ret.GetLogsPrinting   = flags.HasFlag(SenseCollectorVariableTypes.PrintingLogs);
            ret.GetLogsScripting  = flags.HasFlag(SenseCollectorVariableTypes.ScriptLogs);
            return(ret);
        }
        public void LoadAndRead(DirectorySetting[] directories, CommonCollectorServiceVariables settings)
        {
            _settings = settings;

            if (!settings.GetLogsScripting)
            {
                _ignoredFiles = SenseLogBaseTypes.Script;
            }

            var cts = new CancellationTokenSource();
            var cancellationToken = cts.Token;

            _folderNotificationHelper = new FolderNotificationHelper(_logger, _notify, NotificationKey, _settings);

            Task.Run(async() =>
            {
                while (true)
                {
                    await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
                    _folderNotificationHelper.Analyze(_localFileCounter, _localDirCounter);
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }, cancellationToken);


            foreach (DirectorySetting directory in directories)
            {
                CrawlAllLogBaseDirectories(directory);
            }
            cts.Cancel();
            //_onLogDirectorFinishedReading?.Invoke(this);
        }
Ejemplo n.º 6
0
        public string CreateZipFile(CommonCollectorServiceVariables serviceVariables)
        {
            string path     = serviceVariables.OutputFolderPath;
            var    a        = new Zipper(path);
            var    fileName = serviceVariables.ApplicatonBaseName + "_" + serviceVariables.Key;

            return(a.ZipFolder(path, fileName, Path.GetFullPath(Path.Combine(serviceVariables.OutputFolderPath, @".."))));
        }
Ejemplo n.º 7
0
 public FolderNotificationHelper(ILogger logger, Action <string, MessageLevels, string> notify, string notificationKey, CommonCollectorServiceVariables serviceVariables)
 {
     _logger           = logger;
     _notify           = notify;
     _notificationKey  = notificationKey;
     _serviceVariables = serviceVariables;
     _notify(_msg, MessageLevels.Animate, _notificationKey);
 }
        public async Task <bool> GetLogs(string path, CommonCollectorServiceVariables settings, string outputFilePath)
        {
            try
            {
                _settings = settings;
                FindLogFiles(_fileSystem.Path.Combine(path, "ProgramData\\Qlik\\Custom Data"), _fileSystem.Path.Combine(outputFilePath, "ConnectorLogs"));
            }
            catch
            {
                _logger.Add($"Failed getting Connector GetLogs on {path}");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
        public Runner(ILogger logger, Form owner)
        {
            _logger = logger;
            _owner  = owner;
            var name = Process.GetCurrentProcess().ProcessName;

            try
            {
                Settings = new FileNamingProcessor().DecodeFileName(name);
            }
            catch (Exception e)
            {
                Settings = new CommonCollectorServiceVariables();
                _logger.Add($"The filenaming processor failed decoding variables for name {name} and got {e}");
            }
        }
        public async Task <bool> GetLogs(string path, CommonCollectorServiceVariables settings, string outputFilePath)
        {
            try
            {
                _settings = settings;
                await WriteNPrintingInfo(path, outputFilePath).ConfigureAwait(false);

                FindLogFiles(_fileSystem.Path.Combine(path, "ProgramData\\NPrinting\\Logs"), _fileSystem.Path.Combine(outputFilePath, "NPrintingLogs"));
            }
            catch
            {
                _logger.Add($"Failed getting NPrinting GetLogs on {path}");
                return(false);
            }

            return(true);
        }
        public string CreateFileNameProperties(CommonCollectorServiceVariables variables)
        {
            SenseCollectorVariableTypes flags = SenseCollectorVariableTypes.Unknown;

            if (variables.AllowWindowsLogs)
            {
                flags |= SenseCollectorVariableTypes.AllowWindowsLogs;
            }
            if (variables.AllowMachineInfo)
            {
                flags |= SenseCollectorVariableTypes.AllowMachineInfo;
            }
            if (variables.UseOnlineDelivery)
            {
                flags |= SenseCollectorVariableTypes.UseOnlineDelivery;
            }
            if (variables.GetLogsMain)
            {
                flags |= SenseCollectorVariableTypes.MainLogs;
            }
            if (variables.GetLogsPrinting)
            {
                flags |= SenseCollectorVariableTypes.PrintingLogs;
            }
            if (variables.GetLogsScripting)
            {
                flags |= SenseCollectorVariableTypes.ScriptLogs;
            }

            var str = variables.StartDateForLogs.ToString("yyMMdd") +
                      variables.StopDateForLogs.ToString("yyMMdd") +
                      ((int)flags).ToString().PadLeft(3, '0') +
                      variables.Key + "";

            var filepart = _encoder.Encode(BigInteger.Parse(str));
            var test     = _encoder.Decode(filepart).ToString();

            if (!test.Equals(str))
            {
                throw new Exception("whow somehow our magic string thingy did not generate a correct output.");
            }

            return(filepart);
        }
Ejemplo n.º 12
0
        public void Execute(CommonCollectorServiceVariables serviceVariables)
        {
            _serviceVariables = serviceVariables;
            //_serviceVariables.QvSettings.QvLogLocations = new List<QvLogLocation>();
            //_serviceVariables.QvSettings.QvLogLocations.Add(new QvLogLocation
            //{
            //    Name = $"CommonFiles - QlikTech - su-pubdev2",
            //    Type = QvLogLocationSource.QdsClusterInfoUrl,
            //    Path = $"\\\\su-pubdev2\\c$\\ProgramData\\QlikTech",
            //    LogCollectionType = QvLogCollectionType.SettingsOnly
            //});
            var cts = new CancellationTokenSource();
            var cancellationToken = cts.Token;

            _folderNotificationHelper = new FolderNotificationHelper(_logger, _notify, _notificationKey, _serviceVariables);

            Task.Run(async() =>
            {
                while (true)
                {
                    await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
                    _folderNotificationHelper.Analyze(_localFileCounter, _localDirCounter);
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }, cancellationToken);

            _serviceVariables.QvSettings.QvLogLocations.ForEach(p =>
            {
                _folderNotificationHelper.SetCurrentFolderNames(p.Name, null);
                CrawlAllLogBaseDirectories(new DirectorySetting(p.Path), p.Name, p.IgnorePaths);
                p.AddToFileCount(_localFileCounter);
                Interlocked.Exchange(ref _localFileCounter, 0);
                Interlocked.Exchange(ref _localDirCounter, 0);
            });
            cts.Cancel();
            _notify($"{FoundFileCount} logs found on {_serviceVariables.QvSettings.QvLogLocations.Count} locations.", MessageLevels.Ok, _notificationKey);
        }
Ejemplo n.º 13
0
 public CollectorHelper(CommonCollectorServiceVariables settings, ILogger logger)
 {
     _settings = settings;
     _logger   = logger;
 }
 public Task ReadRemoteLogs(IEnumerable <QlikSenseMachineInfo> qlikSenseMachineInfos, CommonCollectorServiceVariables settings)
 {
     return(Task.Run(
                async() =>
     {
         foreach (var info in qlikSenseMachineInfos)
         {
             var director = new StreamLogDirector(_logger, _notify)
             {
                 FriendlyName = "Remote Logs " + info.Name, NotificationKey = "RemoteLogs"
             };
             var path = $@"\\{info.HostName}\c$\ProgramData\Qlik\Sense\Log";
             //director.OnLogDirectorFinishedReading(LogDirectorDone);
             _logger.Add($"Started reading remote Logs from {info.Name} at {path}");
             director.LoadAndRead(new[] { new DirectorySetting(path) }, settings);
             TotalNumberOfRemoteLogFiles += director.FoundFileCount;
             _logger.Add($"Started reading NPrinting logs at {$@"\\{info.HostName}\c$"}");
             await new NPrintingCollector(FileSystem.Singleton, _logger).GetLogs($@"\\{info.HostName}\c$", settings, FileSystem.Singleton.Path.Combine(settings.OutputFolderPath, info.HostName)).ConfigureAwait(false);
             _logger.Add($"Started reading Connector logs at {$@"\\{info.HostName}\c$"}");
             await new ConnectorsLogCollector(FileSystem.Singleton, _logger).GetLogs($@"\\{info.HostName}\c$", settings, FileSystem.Singleton.Path.Combine(settings.OutputFolderPath, info.HostName)).ConfigureAwait(false);
             _logger.Add($"Finished reading logs from {info.Name}");
         }
     }).ContinueWith(p =>
     {
         _onFinished.Invoke(new StreamLogDirector(_logger, _notify)
         {
             FriendlyName = "Remote Logs", NotificationKey = "RemoteLogs", FoundFileCount = TotalNumberOfRemoteLogFiles
         });
     }));
 }