private string setHTMLSelectView(object sender, bool isEmail)
        {
            try
            {
                var olv = sender as BrightIdeasSoftware.ObjectListView;

                //If nothing is selected, show a dark empty background
                if (olv == null || (!isEmail && olv.SelectedItems.Count < 1))
                {
                    return("<body style = \"background-color: #2b2b2b\" />");
                }

                int itemCount     = 0;
                var htmlFormatter = new HTMLFormatter();

                if (isEmail)
                {
                    itemCount = olv.Items.Count;
                    htmlFormatter.SetBody(null, ("FiOS Health Check - " + DateTime.Today.ToString("MM/dd/yyyy")));
                }
                else
                {
                    itemCount = olv.SelectedItems.Count;
                    htmlFormatter.SetBody("#777677");
                }

                //Create an array since OLV Item collections does not have an enumerator for linq
                BrightIdeasSoftware.OLVListItem[] selectedOlvLis = new BrightIdeasSoftware.OLVListItem[itemCount];

                //If email, copy all items in OLV to array. Otherwise copy only selected items.
                if (isEmail)
                {
                    olv.Items.CopyTo(selectedOlvLis, 0);
                }
                else
                {
                    olv.SelectedItems.CopyTo(selectedOlvLis, 0);
                }

                //Group health rollups on the server role to be able to display the results under each role
                var roles = selectedOlvLis.Select(x => x.RowObject as HealthRollup).GroupBy(x => x.Server.HostRole)
                            .Select(x => new { x.Key, HostNames = x.Select(y => y.Server) });

                //loop through each role, creating the selected servers and displaying their result and any errors if they exist
                foreach (var role in roles.OrderBy(x => x.Key))
                {
                    htmlFormatter.SetRole(role.Key.ToString());

                    foreach (var svr in role.HostNames.OrderBy(x => !x.IsActive).ThenBy(x => x.HostName))
                    {
                        if (!svr.IsActive)
                        {
                            htmlFormatter.BeginTable(string.Format("{0} (Inactive)", svr.HostName), "#2f285b");
                        }
                        else
                        {
                            htmlFormatter.BeginTable(svr.HostName);
                        }

                        var hru = selectedOlvLis.Select(x => x.RowObject as HealthRollup).Where(x => x.Server.HostName.Equals(svr.HostName)).FirstOrDefault();

                        foreach (var err in hru.Errors)
                        {
                            writeVerbose(string.Format("{0} has {1} errors for check type {2}. Result: {3}", svr.HostName, err.Error.Count, err.HCType, err.Result));
                            htmlFormatter.AddStatusRow(err.HCType.ToString(), err.Result);
                            if (err.Error.Count > 0)
                            {
                                writeVerbose(string.Format("{0} - Check Type {1} - Errors: {2}", svr.HostName, err.HCType, string.Join(System.Environment.NewLine, err.Error)));
                                htmlFormatter.AddErrorDescriptionRows(err.Error);
                            }
                        }

                        htmlFormatter.EndTable();
                    }
                }
                return(htmlFormatter.ToString());
            }
            catch (Exception ex)
            {
                writeError(string.Format("Error in selection changed delegate. {0}", ex.Message), 10900, System.Diagnostics.TraceEventType.Error);
                return(string.Empty);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            var server = ServerConfigMgr.GetServers().Where(x => x.HostName.ToUpper().Equals("CTXV01PIMGD01")).FirstOrDefault();

            bool isExempt = ServerHealthCheckConfigMgr.IsExempt(server, ExemptionType.HardDrive, "O");


            var winServicesToCheck = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck()
                                     .Where
                                     (
                x => x.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && x.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0 ||
                x.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && x.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0 ||
                !x.Function.Equals(ServerFunction.Unknown) && (x.Function.Equals(server.HostFunction) && x.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + x.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0) ||
                ((x.Roles.Count + x.Servers.Count == 0) && (x.Function.Equals(ServerFunction.Unknown)))
                                     ).ToArray();


            //hcWServices = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.OnePerGroup).ToArray();

            foreach (var svc in ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.Name == "WAS"))
            {
                var count  = svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count();
                var count2 = svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count();

                //if (svc.Roles.Count >= 1)
                //svc.Roles.ForEach(x => Console.WriteLine("{3}  - {0} | {1} | {2}", x.Item1, x.Item2, x.Item3, svc.Name));

                bool bol1 = svc.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0;
                bool bol2 = svc.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0;
                bool bol3 = (svc.Function.Equals(server.HostFunction) && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0);
                bool bol4 = ((svc.Roles.Count + svc.Servers.Count == 0) && (svc.Function.Equals(ServerFunction.Unknown)));
                bool bol5 = svc.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0 ||
                            svc.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0 ||
                            (svc.Function.Equals(server.HostFunction) && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0) ||
                            ((svc.Roles.Count + svc.Servers.Count == 0) && (svc.Function.Equals(ServerFunction.Unknown)));

                Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8}", svc.Name, count, server.HostFunction, server.HostRole, count2, bol1, bol2, bol3, bol4, bol5);
            }

            //var roleCheck = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.Roles.Where(y => y.Item1 && y.Item2 == svr.HostRole).Count() > 0);

            foreach (var service in winServicesToCheck)
            {
                Console.WriteLine("Name:\t\t{0}", service.Name);
                Console.WriteLine("Display:\t{0}", service.DisplayName);
                if (service.CheckStatus.Count > 0)
                {
                    service.CheckStatus.ForEach(x => Console.WriteLine("Status:\t\t{0}", x.ToString()));
                }
                if (service.CheckStartupType.Count > 0)
                {
                    service.CheckStartupType.ForEach(x => Console.WriteLine("StartupType:\t{0}", x.ToString()));
                }
                if (service.CheckLogonAs.Count > 0)
                {
                    service.CheckLogonAs.ForEach(x => Console.WriteLine("LogonAs:\t{0} - {1}", x, GenericChecks.GetWindowsServiceLogonAccount("B1ZHN32", service.Name)));
                }
                if (service.Roles.Count > 0)
                {
                    service.Roles.ForEach((x) =>
                    {
                        if (x.Item1)
                        {
                            Console.WriteLine("INCLUDE ROLES");
                        }
                        else
                        {
                            Console.WriteLine("EXCLUDE ROLES");
                        }
                        Console.WriteLine("Role:\t\t{0}", x.Item2.ToString());
                        Console.WriteLine("Function:\t{0}", x.Item3.ToString());
                    });
                }
                if (service.Servers.Count > 0)
                {
                    service.Servers.ForEach((x) =>
                    {
                        if (x.Item1)
                        {
                            Console.WriteLine("INCLUDE SERVERS");
                        }
                        else
                        {
                            Console.WriteLine("EXCLUDE SERVERS");
                        }

                        Console.WriteLine("Server Name:\t{0}", x.Item2.HostName);
                        Console.WriteLine("Server IP:\t{0}", x.Item2.IPAddress);
                        Console.WriteLine("Server Location:\t{0}", x.Item2.HostLocation.ToString());
                    });
                }
                Console.WriteLine("OnePerGroup:\t{0}", service.OnePerGroup);
                Console.WriteLine();
            }
            Console.WriteLine("Press Enter to Continue...");
            Console.ReadLine();

            HTMLFormatter formatter = new HTMLFormatter();

            formatter.SetRole(ServerRole.NSP.ToString());

            formatter.BeginTable("NSPTXCAWAPV01");
            formatter.AddStatusRow("Server Status", StatusResult.Ok);
            formatter.AddStatusRow("Web Services", StatusResult.Error);
            List <string> errors = new List <string>();

            errors.Add("Config file mismatch with NSPTXCAWAPV02");
            errors.Add("Web API returned error");
            formatter.AddErrorDescriptionRows(errors);

            formatter.AddStatusRow("Database", StatusResult.Error);
            errors.Clear();
            errors.Add("Missing data in table");
            formatter.AddErrorDescriptionRows(errors);
            formatter.EndTable();

            formatter.BeginTable("NSPTXCAWAPV02");
            formatter.AddStatusRow("Server Status", StatusResult.Ok);
            formatter.AddStatusRow("Web Services", StatusResult.Error);
            errors.Clear();
            errors.Add("Config file mismatch with NSPTXCAWAPV01");
            formatter.AddErrorDescriptionRows(errors);
            formatter.AddStatusRow("Database", StatusResult.Ok);
            formatter.EndTable();

            formatter.BeginTable("NSPTXCAWAPV03");
            formatter.AddStatusRow("Server Status", StatusResult.Critical);
            errors.Clear();
            errors.Add("Server is unreachable.");
            formatter.AddErrorDescriptionRows(errors);
            formatter.AddStatusRow("Web Services", StatusResult.Ok);
            formatter.AddStatusRow("Database", StatusResult.Ok);
            formatter.EndTable();


            Toolset.SendEmail("mailrelay.corp.pvt", null, 25, false, "HealthCheck Test Email", formatter.ToString(), "*****@*****.**", new string[1] {
                "*****@*****.**"
            }, null);

            var servers = ServerConfigMgr.GetServers().ToList();

            foreach (var svr in servers.Where(x => x.HostRole == ServerRole.IMG))
            {
                if (svr is FiOSDbServer)
                {
                    Console.WriteLine("\nDATABASE:\n");
                    Console.WriteLine((svr as FiOSDbServer).DatabaseType);
                }
                else if (svr is FiOSWebServer)
                {
                    Console.WriteLine("\nIIS SERVER:\n");
                }
                else
                {
                    Console.Write("\nFiOS Server:\n");
                }

                Console.WriteLine(svr.HostName);
                Console.WriteLine(svr.HostFullName);
                Console.WriteLine(svr.HostFunction);
                Console.WriteLine(svr.HostLocation);
                Console.WriteLine(svr.HostLocationName);
                Console.WriteLine(svr.HostName);
                Console.WriteLine(svr.HostRole);
                Console.WriteLine(svr.IsOnline);

                try
                {
                    if (svr is FiOSWebServer)
                    {
                        using (var iisMgr = new IISServerMgr(svr))
                        {
                            try
                            {
                                var Sites = iisMgr.GetSiteCollection();
                                foreach (var site in Sites)
                                {
                                    Console.WriteLine("Site: {0} - {1} - {2}", site.Name, site.ServerAutoStart, site.State);

                                    foreach (var app in site.Applications)
                                    {
                                        Console.WriteLine("App Pool: {0} - {1}", app.ApplicationPoolName, app.Path);

                                        foreach (var vd in app.VirtualDirectories)
                                        {
                                            Console.WriteLine("Virtual Dir: {0} - {1}", vd.Path, vd.PhysicalPath);
                                            foreach (var attr in vd.Attributes)
                                            {
                                                Console.WriteLine("Attribute: {0} - {1}", attr.Name, attr.Value);
                                            }

                                            foreach (var ce in vd.ChildElements)
                                            {
                                                foreach (var attr in ce.Attributes)
                                                {
                                                    Console.WriteLine("Child Attribute: {0} - {1}", attr.Name, attr.Value);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Failed to get Sites for {0}. {1}", svr.HostName, ex.Message);
                                Console.ResetColor();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("General Error: {0}", ex.Message);
                    Console.ResetColor();
                }
            }

            Console.WriteLine("\n\nPress any key to exit...");
            Console.ReadLine();
        }