public void TestConfigOverrides()
        {
            var fileMap = new ConfigurationFileMap(Path.GetFullPath(@"Configs\EdbOverridesConfig.config"));
            var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            var config = configuration.GetSection("LogSearchShipperGroup/LogSearchShipper") as LogSearchShipperSection;

            {
                var edbItem = config.EDBFileWatchers[0];
                var overrideConfig = edbItem.OverrideConfigs.First();
                var edbFileWatchParser = new EDBFileWatchParser(edbItem);
                var fileWatchItems = edbFileWatchParser.ToFileWatchCollection();
                Assert.AreEqual(5, fileWatchItems.Count);

                var matchedItems = fileWatchItems.Where(item => item.Files.Contains("Price")).ToArray();
                Assert.AreEqual(2, matchedItems.Count());
                Assert.IsTrue(matchedItems.All(item => item.CloseWhenIdle == false));
                Assert.IsTrue(matchedItems.All(item => item.CustomNxlogConfig.Value == overrideConfig.CustomNxlogConfig.Value));
                Assert.IsTrue(matchedItems.All(item => item.SourceTailer == TailerType.MT));
                Assert.IsTrue(matchedItems.All(item => item.Fields["environment"].Value == "CUSTOM_VALUE"));

                var notMatchedItems = fileWatchItems.ToList();
                foreach (var item in matchedItems)
                {
                    notMatchedItems.Remove(item);
                }

                Assert.IsTrue(notMatchedItems.Count > 0);
                Assert.IsTrue(notMatchedItems.All(item => item.CloseWhenIdle == true));
                Assert.IsTrue(notMatchedItems.All(item => string.IsNullOrEmpty(item.CustomNxlogConfig.Value)));
                Assert.IsTrue(notMatchedItems.All(item => item.SourceTailer == TailerType.Normal));
                Assert.IsTrue(notMatchedItems.All(item => item.Fields["environment"].Value == "QAT"));
            }
        }
        public void ShouldGenerateConfiguredFileWatches()
        {
            var config = ConfigurationManager.GetSection("LogSearchShipperGroup/LogSearchShipper") as LogSearchShipperSection;
            var edbFileWatchParser = new EDBFileWatchParser(config.EDBFileWatchers[1]);
            var fileWatches = edbFileWatchParser.ToFileWatchCollection();

            Assert.AreEqual(6, fileWatches.Count, "edbFileWatch filters not working correctly");

            Assert.AreEqual("\\\\PKH-STG-WEB01\\Logs\\Nolio\\all.log", fileWatches[0].Files);
            Assert.AreEqual("log4j", fileWatches[0].Type);

            Assert.AreEqual("\\\\PKH-STG-WEB01\\Logs\\Nolio\\include1.log", fileWatches[1].Files);
            Assert.AreEqual("log4j1", fileWatches[1].Type);

            Assert.AreEqual("\\\\PKH-STG-PRICE01\\Logs\\Nolio\\include2.log", fileWatches[3].Files);
            Assert.AreEqual("log4j2", fileWatches[3].Type);

            var fileWatch = fileWatches[0];

            var hostField = fileWatch.Fields["host"];
            Assert.AreEqual("PKH-STG-WEB01", hostField.Value);

            var serviceField = fileWatch.Fields["service"];
            Assert.AreEqual("nolioagent2", serviceField.Value);

            var environmentField = fileWatch.Fields["environment"];
            Assert.AreEqual("ENV2", environmentField.Value);
        }
 public string GenerateJsonForWatch0()
 {
     var config = ConfigurationManager.GetSection("LogSearchShipperGroup/LogSearchShipper") as LogSearchShipperSection;
     var edbFileWatchParser = new EDBFileWatchParser(config.EDBFileWatchers[0]);
     IEnumerable<EDBEnvironment> environmentHierarchy = edbFileWatchParser.GenerateLogsearchEnvironmentDiagram();
     string environmentHierarchyJSON = JsonConvert.SerializeObject(environmentHierarchy, Formatting.None);
     Console.WriteLine(environmentHierarchyJSON);
     return environmentHierarchyJSON;
 }
        public static void LogEnvironmentData(object state)
        {
            try
            {
                var parser = new EDBFileWatchParser((EnvironmentWatchElement)state);
                IEnumerable<EDBEnvironment> environments = parser.GenerateLogsearchEnvironmentDiagram();

                _log.Info(string.Format("Logged environment diagram data for {0}",
                    string.Join(",", environments.Select(e => e.Name))));

                LogManager.GetLogger("EnvironmentDiagramLogger").Info(new { Environments = environments });

                EdbDataFormatter.ReportData(environments);
            }
            catch (Exception exc)
            {
                _log.Error(exc);
            }
        }
        private void ExtractEDBFileWatchers(LogSearchShipperSection LogSearchShipperConfig, List<FileWatchElement> watches)
        {
            for (int i = 0; i < LogSearchShipperConfig.EDBFileWatchers.Count; i++)
            {
                EnvironmentWatchElement envWatchElement = LogSearchShipperConfig.EDBFileWatchers[i];

                StartLoggingEnvironmentData(envWatchElement);
                AddWatchedConfigFile(envWatchElement.DataFile);

                var parser = new EDBFileWatchParser(envWatchElement);
                watches.AddRange(parser.ToFileWatchCollection());
            }
        }
        public void TestEdbNotMatchElements()
        {
            var fileMap = new ConfigurationFileMap(Path.GetFullPath(@"Configs\EdbNotMatch.config"));
            var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            var config = configuration.GetSection("LogSearchShipperGroup/LogSearchShipper") as LogSearchShipperSection;

            {
                var edbFileWatchParser = new EDBFileWatchParser(config.EDBFileWatchers[0]);
                var watchElements = edbFileWatchParser.ToFileWatchCollection();
                Assert.AreEqual(1, watchElements.Count);
                Assert.IsTrue(!watchElements.First().Files.Contains("ENV1"));
                Assert.IsTrue(watchElements.First().Files.Contains("-ENV2-"));
            }
        }