Ejemplo n.º 1
0
        /// <summary>
        /// Copies all log files to the local disk in the temporary folder.
        /// </summary>
        /// <param name="container"></param>
        public void CopyToLocalDisk(ServerLogFileContainer container)
        {
            if (!container.AppLogFiles.Any())
                return;

            string tempRoot = Path.Combine(Path.GetTempPath(), "Kelpie", container.Server.Name);
            if (!Directory.Exists(tempRoot))
                Directory.CreateDirectory(tempRoot);

            foreach (AppLogFiles appLogFile in container.AppLogFiles)
            {
                string destAppDirectory = Path.Combine(tempRoot, appLogFile.Appname);

                if (!Directory.Exists(destAppDirectory))
                    Directory.CreateDirectory(destAppDirectory);

                Parallel.ForEach(appLogFile.LogfilePaths, (filePath) =>
                {
                    if (File.GetLastWriteTime(filePath) >= DateTime.UtcNow.AddDays(-_configuration.MaxAgeDays))
                    {
                        // Copy the log file to the %TEMP%/{appName}/ directory
                        string sourceDir = Path.GetDirectoryName(filePath);

                        LogLine("- Copying {0} to local disk", filePath);
                        string destFilePath = filePath.Replace(sourceDir, destAppDirectory);

                        File.Copy(filePath, destFilePath, true);

                        appLogFile.UpdatePath(filePath, destFilePath);
                    }
                    else
                    {
                        LogLine("- Ignoring {0} as it's more than {1} days old", filePath, _configuration.MaxAgeDays);
                    }
                });
            }
        }
Ejemplo n.º 2
0
        private ServerLogFileContainer CreateContainer(string logPath)
        {
            var server = new Server()
            {
                CopyFilesToLocal = true,
                Name = "server",
                Username = "******",
                Password = "******",
                Path = ""
            };
            var environment = new Environment() { Name = "environment" };
            environment.Servers.Add(server);

            var appLogFiles = new List<AppLogFiles>();
            appLogFiles.Add(new AppLogFiles()
            {
                LogfilePaths = { logPath },
                Appname = APP_NAME
            });

            var container = new ServerLogFileContainer();
            container.Environment = environment;
            container.Server = server;
            container.AppLogFiles = appLogFiles;

            return container;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scans every environment and each server in that environment.
        /// </summary>
        public IEnumerable<ServerLogFileContainer> ScanAllEnvironments()
        {
            var list = new List<ServerLogFileContainer>();

            foreach (Environment environment in _configuration.Environments)
            {
                foreach (Server server in environment.Servers)
                {
                    IEnumerable<AppLogFiles> apps = GetLogfilePaths(server);
                    var container = new ServerLogFileContainer()
                    {
                        Server = server,
                        Environment = environment,
                        AppLogFiles = apps
                    };
                    list.Add(container);
                }
            }

            return list;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scans a single server's log files.
        /// </summary>
        /// <param name="serverName">The name of the server, which should match the kelpie.config file.</param>
        public ServerLogFileContainer ScanSingleServer(string serverName)
        {
            foreach (Environment environment in _configuration.Environments)
            {
                var server = environment.Servers.FirstOrDefault(x => x.Name.Equals(serverName, StringComparison.InvariantCultureIgnoreCase));

                if (server != null)
                {
                    IEnumerable<AppLogFiles> apps = GetLogfilePaths(server);
                    var container = new ServerLogFileContainer()
                    {
                        Server = server,
                        Environment = environment,
                        AppLogFiles = apps
                    };
                    return container;
                }
            }

            return null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Scans all servers for a given environment.
        /// </summary>
        /// <param name="environmentName">The name of the environment, which should match the kelpie.config file.</param>
        public IEnumerable<ServerLogFileContainer> ScanSingleEnvironment(string environmentName)
        {
            var list = new List<ServerLogFileContainer>();

            Environment environment =
                _configuration.Environments.FirstOrDefault(
                    x => x.Name.Equals(environmentName, StringComparison.InvariantCultureIgnoreCase));

            if (environment != null)
            {
                foreach (Server server in environment.Servers)
                {
                    IEnumerable<AppLogFiles> apps = GetLogfilePaths(server);
                    var container = new ServerLogFileContainer()
                    {
                        Server = server,
                        Environment = environment,
                        AppLogFiles = apps
                    };
                    list.Add(container);
                }
            }

            return list;
        }