コード例 #1
0
        private async Task <IEnumerable <FiOSWebServer> > getWebServers(string connectionStr)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("SELECT a.strServerId, a.strServerIP, a.strServerTypeId, b.strVHOId");
            sb.AppendLine("FROM tFiOSServers a (NOLOCK)");
            sb.AppendLine("LEFT OUTER JOIN tFiOSVHOServerMap b (NOLOCK) ON b.strServerId = a.strServerId");

            var result = new List <FiOSWebServer>();
            await DBFactory.SQL_ExecuteReaderAsync(connectionStr, sb.ToString(), System.Data.CommandType.Text, null, (dr) =>
            {
                while (dr.Read())
                {
                    var svr        = new FiOSWebServer();
                    svr.HostName   = dr.GetString(0);
                    svr.IPAddress  = dr.GetString(1);
                    string svrType = dr.GetString(2).ToUpper();
                    svr.HostRole   = svrType.Equals("LOADBAL") ? FiOSRole.IMG : svrType.Equals("DCSLICER") ? FiOSRole.AdminConsole : FiOSRole.Unknown;
                    if (svr.HostRole == FiOSRole.IMG)
                    {
                        svr.HostLocation     = ServerLocation.VHO;
                        svr.HostLocationName = dr.IsDBNull(3) ? null : dr.GetString(3);
                    }
                    else if (svr.HostRole == FiOSRole.AdminConsole)
                    {
                        svr.HostLocation     = ServerLocation.VHE;
                        svr.HostLocationName = "VHE";
                    }
                    svr.HostFunction = ServerFunction.Web;
                    result.Add(svr);
                }
            });

            return(await Task.FromResult <IEnumerable <FiOSWebServer> >(result));
        }
コード例 #2
0
        public static IEnumerable <FiOSServer> GetServers()
        {
            var serverElems = _config.Root.Descendants(_ns + "Server");

            foreach (var serverElem in serverElems)
            {
                if (serverElem.HasAttributes)
                {
                    if (serverElem.Attributes().Any(x => x.Name.LocalName.ToUpper().Equals("FUNCTION")))
                    {
                        if (serverElem.Attribute("Function").Value.ToUpper().Equals("DATABASE"))
                        {
                            string vhoName  = null;
                            var    dbServer = new FiOSDbServer();
                            dbServer.HostFunction     = ServerFunction.Database;
                            dbServer.HostName         = getName(serverElem);
                            dbServer.HostFullName     = getFullName(dbServer.HostName);
                            dbServer.HostLocation     = getLocation(serverElem, out vhoName);
                            dbServer.HostLocationName = vhoName;
                            dbServer.HostRole         = getRole(serverElem, dbServer.HostLocation);
                            dbServer.IPAddress        = getIP(serverElem);
                            dbServer.IsActive         = getIsActive(serverElem);

                            yield return(dbServer);
                        }
                        else if (serverElem.Attribute("Function").Value.ToUpper().Equals("WEB"))
                        {
                            string vhoName   = null;
                            var    webServer = new FiOSWebServer();
                            webServer.HostFunction     = ServerFunction.Web;
                            webServer.HostName         = getName(serverElem);
                            webServer.HostFullName     = getFullName(webServer.HostName);
                            webServer.HostLocation     = getLocation(serverElem, out vhoName);
                            webServer.HostLocationName = vhoName;
                            webServer.HostRole         = getRole(serverElem, webServer.HostLocation);
                            webServer.IPAddress        = getIP(serverElem);
                            webServer.IsActive         = getIsActive(serverElem);

                            yield return(webServer);
                        }
                    }
                    else
                    {
                        string vhoName = null;
                        var    server  = new FiOSServer();
                        server.HostName         = getName(serverElem);
                        server.HostFullName     = getFullName(server.HostName);
                        server.HostLocation     = getLocation(serverElem, out vhoName);
                        server.HostLocationName = vhoName;
                        server.HostRole         = getRole(serverElem, server.HostLocation);
                        server.HostFunction     = serverElem.HasAttributes && serverElem.FirstAttribute.Value.ToUpper().Equals("APP") ? ServerFunction.Application :
                                                  serverElem.Ancestors().Any(x => x.Name.LocalName.ToUpper().Equals("INFRASTRUCTURE")) ||
                                                  serverElem.Ancestors().Any(x => x.Name.LocalName.ToUpper().Equals("DOMAINCONTROLLERS")) ? ServerFunction.Infrastructure : ServerFunction.Unknown;
                        server.IPAddress = getIP(serverElem);
                        server.IsActive  = getIsActive(serverElem);

                        yield return(server);
                    }
                }
                else
                {
                    throw new FormatException("XML Format error. Server element has no attributes.");
                }
            }
        }
コード例 #3
0
        public async Task <HealthRollup> CheckWebServer(FiOSWebServer Server)
        {
            HealthRollup     hru = new HealthRollup();
            HealthCheckError hce = new HealthCheckError();

            hru.Server = Server;
            hce.Result = StatusResult.Ok;
            hce.HCType = HealthCheckType.IIS;

            if (ServerHealthCheckConfigMgr.IsExempt(Server, ExemptionType.IIS))
            {
                hce.Result = StatusResult.Skipped;
                hru.Errors.Add(hce);
                return(await Task.FromResult <HealthRollup>(hru));
            }

            if (!Server.IsOnline)
            {
                hce.Result = StatusResult.Critical;
                hce.Error.Add(string.Format("{0} - Cannot communicate with web services due to the server being unreachable.", StatusResult.Critical));
                hru.Errors.Add(hce);
                return(await Task.FromResult <HealthRollup>(hru));
            }

            try
            {
                using (var iisManager = new IISServerMgr(Server))
                {
                    foreach (var site in iisManager.GetSiteCollection())
                    {
                        switch (site.State)
                        {
                        case ObjectState.Started:
                            break;

                        case ObjectState.Stopped:
                            hce.Result = StatusResult.Critical;
                            hce.Error.Add(string.Format("{0} - IIS Site {1} is in a stopped state.", StatusResult.Critical, site.Name));
                            break;

                        case ObjectState.Stopping:
                            hce.Result = StatusResult.Critical;
                            hce.Error.Add(string.Format("{0} - IIS Site {1} is currently in a stopping state.", StatusResult.Error, site.Name));
                            break;

                        case ObjectState.Starting:
                            hce.Result = StatusResult.Critical;
                            hce.Error.Add(string.Format("{0} - IIS Site {1} is currently starting.", StatusResult.Warning, site.Name));
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                hce.Result = StatusResult.Error;
                hce.Error.Add(string.Format("{0} - Error connecting to IIS. {1}", StatusResult.Error, ex.Message));
            }

            hru.Errors.Add(hce);
            return(await Task.FromResult <HealthRollup>(hru));
        }