Example #1
0
 public bool ConsolidationTask()
 {
     return(StartTask("Healthcheck consolidation",
                      () =>
     {
         HealthcheckAnalyzer hc = new HealthcheckAnalyzer();
         if (String.IsNullOrEmpty(FileOrDirectory))
         {
             FileOrDirectory = Directory.GetCurrentDirectory();
         }
         if (!Directory.Exists(FileOrDirectory))
         {
             WriteInRed("The directory " + FileOrDirectory + " doesn't exist");
             return;
         }
         HealthcheckDataCollection consolidation = HealthcheckDataHelper.LoadXmls(FileOrDirectory, FilterReportDate);
         if (consolidation.Count == 0)
         {
             WriteInRed("No report has been found. The program will stop");
             return;
         }
         HealthCheckReportConsolidation report = new HealthCheckReportConsolidation(consolidation);
         report.GenerateReportFile("ad_hc_summary.html");
         HealthCheckReportMapBuilder nodeAnalyzer = new HealthCheckReportMapBuilder(consolidation);
         nodeAnalyzer.Log = Console.WriteLine;
         nodeAnalyzer.GenerateReportFile("ad_hc_summary_full_node_map.html");
         nodeAnalyzer.FullNodeMap = false;
         nodeAnalyzer.CenterDomainForSimpliedGraph = CenterDomainForSimpliedGraph;
         nodeAnalyzer.GenerateReportFile("ad_hc_summary_simple_node_map.html");
     }
                      ));
 }
Example #2
0
        public static HealthcheckDataCollection LoadXmls(string Xmls, DateTime maxfiltervalue)
        {
            HealthcheckDataCollection output = new HealthcheckDataCollection();
            int files = 0;

            foreach (string filename in Directory.GetFiles(Xmls, "*.xml", SearchOption.AllDirectories))
            {
                try
                {
                    files++;
                    HealthcheckData healthcheckData = DataHelper <HealthcheckData> .LoadXml(filename);

                    // taking the more recent report
                    if (healthcheckData.GenerationDate > maxfiltervalue)
                    {
                        Trace.WriteLine("File " + filename + " ignored because generation date " + healthcheckData.GenerationDate.ToString("u") + " is after the consolidation date " + maxfiltervalue.ToString("u"));
                        continue;
                    }
                    output.Add(healthcheckData);
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unable to load the file " + filename + " (" + ex.Message + ")");
                    Console.ResetColor();
                    Trace.WriteLine("Unable to load the file " + filename + " (" + ex.Message + ")");
                    Trace.WriteLine(ex.StackTrace);
                }
            }
            Console.WriteLine("Reports loaded: " + output.Count + " - on a total of " + files + " valid files");
            return(output);
        }
Example #3
0
        public static HealthcheckDataCollection TransformReportsToDemo(HealthcheckDataCollection consolidation)
        {
            string rotKey = GenerateRandomRotKey();

            HealthcheckDataCollection output = new HealthcheckDataCollection();

            foreach (HealthcheckData data in consolidation)
            {
                HealthcheckData demoreport = TransformReportToDemo(rotKey, data);
                output.Add(demoreport);
            }
            return(output);
        }
Example #4
0
 public bool GenerateDemoReportTask()
 {
     return(StartTask("Generating demo reports",
                      () =>
     {
         if (String.IsNullOrEmpty(FileOrDirectory))
         {
             FileOrDirectory = Directory.GetCurrentDirectory();
         }
         if (!Directory.Exists(FileOrDirectory))
         {
             WriteInRed("The directory " + FileOrDirectory + " doesn't exist");
             return;
         }
         string path = Path.Combine(FileOrDirectory, "demo");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         HealthcheckDataCollection consolidation = HealthcheckDataHelper.LoadXmls(FileOrDirectory, FilterReportDate);
         if (consolidation.Count == 0)
         {
             WriteInRed("No report has been found. The program will stop");
             return;
         }
         consolidation = HealthcheckDataHelper.TransformReportsToDemo(consolidation);
         foreach (HealthcheckData data in consolidation)
         {
             string domain = data.DomainFQDN;
             HealthCheckReportSingle report = new HealthCheckReportSingle(data, License);
             string newfile = Path.Combine(path, "ad_hc_" + domain + ".html");
             string html = report.GenerateReportFile(newfile);
             newfile = Path.Combine(path, "ad_hc_" + domain + ".xml");
             data.Level = ExportLevel;
             string xml = DataHelper <HealthcheckData> .SaveAsXml(data, newfile, EncryptReport);
         }
     }
                      ));
 }
Example #5
0
        public bool CartoTask(bool PerformHealthCheckGenerateDemoReports)
        {
            List <HealthcheckAnalyzer.ReachableDomainInfo> domains = null;

            StartTask("Exploration",
                      () =>
            {
                HealthcheckAnalyzer hcroot = new HealthcheckAnalyzer();
                domains = hcroot.GetAllReachableDomains(ADWSPort, Credential);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("List of domains that will be queried");
                Console.ResetColor();
                foreach (var domain in domains)
                {
                    Console.WriteLine(domain.domain);
                }
            });
            HealthcheckDataCollection consolidation = new HealthcheckDataCollection();

            StartTask("Examining all domains in parallele (this can take a few minutes)",
                      () =>
            {
                BlockingQueue <string> queue = new BlockingQueue <string>(30);
                int numberOfThread           = 100;
                Thread[] threads             = new Thread[numberOfThread];
                try
                {
                    ThreadStart threadFunction = () =>
                    {
                        for (; ;)
                        {
                            string domain = null;
                            if (!queue.Dequeue(out domain))
                            {
                                break;
                            }
                            try
                            {
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Starting the analysis of " + domain);
                                HealthcheckAnalyzer hc     = new HealthcheckAnalyzer();
                                hc.NumberOfDepthForSplit   = NumberOfDepthForSplit;
                                hc.AnalyzeReachableDomains = AnalyzeReachableDomains;
                                hc.GenerateCartoReport(domain, ADWSPort, Credential);
                                consolidation.Add(hc.healthcheckData);
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Analysis of " + domain + " completed with success");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] " + "Analysis of " + domain + " failed");
                                Trace.WriteLine("Exception while analysing domain " + domain + " : " + ex.Message);
                                Trace.WriteLine(ex.StackTrace);
                            }
                        }
                    };
                    // Consumers
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        threads[i] = new Thread(threadFunction);
                        threads[i].Start();
                    }
                    foreach (var domain in domains)
                    {
                        queue.Enqueue(domain.domain);
                    }
                    queue.Quit();
                    Trace.WriteLine("examining domains file completed. Waiting for worker thread to complete");
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        threads[i].Join();
                    }
                    Trace.WriteLine("Done examining domains");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Exception while analysing domain in carto: " + ex.Message);
                    Trace.WriteLine(ex.StackTrace);
                }
                finally
                {
                    queue.Quit();
                    for (int i = 0; i < numberOfThread; i++)
                    {
                        if (threads[i] != null)
                        {
                            if (threads[i].ThreadState == System.Threading.ThreadState.Running)
                            {
                                threads[i].Abort();
                            }
                        }
                    }
                }
            });
            if (PerformHealthCheckGenerateDemoReports)
            {
                Console.WriteLine("Performing demo report transformation");
                Trace.WriteLine("Performing demo report transformation");
                consolidation = HealthcheckDataHelper.TransformReportsToDemo(consolidation);
            }
            if (!StartTask("Healthcheck consolidation",
                           () =>
            {
                HealthcheckAnalyzer hc = new HealthcheckAnalyzer();
                HealthCheckReportMapBuilder nodeAnalyzer = new HealthCheckReportMapBuilder(consolidation);
                nodeAnalyzer.Log = Console.WriteLine;
                nodeAnalyzer.CenterDomainForSimpliedGraph = CenterDomainForSimpliedGraph;
                nodeAnalyzer.GenerateReportFile("ad_carto_full_node_map.html");
                nodeAnalyzer.FullNodeMap = false;
                nodeAnalyzer.CenterDomainForSimpliedGraph = CenterDomainForSimpliedGraph;
                nodeAnalyzer.GenerateReportFile("ad_carto_simple_node_map.html");
            }
                           ))
            {
                return(false);
            }
            return(true);
        }