public string GetEIDMReport() { try { //var result = Helper.SendEmail("*****@*****.**", "*****@*****.**", "Test Email", "Testing email"); PoolData poolData = new PoolData(); PoolReport poolReport = new PoolReport(); using (AppPMMEntities Db = new AppPMMEntities()) { // get data from servers Db.Database.ExecuteSqlCommand("DELETE FROM PoolMemberInfoForWeb;DELETE FROM F5Pool;"); List <ActiveDevice> activeDevices = Db.Database.SqlQuery <ActiveDevice>("SELECT DISTINCT REPLACE(REPLACE(REPLACE(DeviceName,'.RDCMS.EDS.COM',''),'.RDCMS.EDS.com',''),'02','01') AS DeviceName FROM MasterDeviceList WHERE active = 1 ORDER BY DeviceName").ToList(); foreach (var device in activeDevices) { poolData.GetPool(Db, device.DeviceName); } // create pdf report var html = poolReport.CreateReport(Db); return(html); } } catch (Exception ex) { Helper.LogError(ex.Message); return(ex.Message); } }
public void GetPool(AppPMMEntities Db, string deviceName) { var responseContent = ""; try { ICR icr = new ICR(ApiAccount, ApiPassword); IRestResponse response = icr.EstablishConnection("/mgmt/tm/ltm/pool", deviceName); responseContent = response.Content; //Helper.LogError(responseContent); var data = JsonConvert.DeserializeObject <RootPoolObject>(responseContent, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }); if (data != null) { var pools = data.items.ToList(); foreach (var pool in pools) { F5Pool f5Pool = new F5Pool(); f5Pool.DeviceName = deviceName; f5Pool.Name = pool.name; f5Pool.Monitor = pool.monitor; f5Pool.LoadBalancingMode = pool.loadBalancingMode; ParsePoolStats.PoolStatsRootObject stats = GetPoolStats(pool.name, deviceName); f5Pool.StatusAvailabilityState = stats.entries.STATS.nestedStats.entries.statusavailabilityState.description; f5Pool.StatusEnabledState = stats.entries.STATS.nestedStats.entries.statusenabledState.description; f5Pool.StatusStatusReason = stats.entries.STATS.nestedStats.entries.statusstatusReason.description; f5Pool.CurSessions = stats.entries.STATS.nestedStats.entries.curSessions.value; f5Pool.TotRequests = stats.entries.STATS.nestedStats.entries.totRequests.value; Db.F5Pool.Add(f5Pool); Db.SaveChanges(); // get pool members GetPoolMemberStats(Db, f5Pool.F5PoolId, pool.name, deviceName); } } } catch (Exception ex) { Helper.LogError(ex.Message + "\r\n" + responseContent + "\r\n"); } }
public static string GetSiteSettingValue(string dbName, string settingName) { if (dbName.ToLower() == "networkcafe") { using (AppNetworkCafeEntities Db = new AppNetworkCafeEntities()) { var settingValue = Db.Database.SqlQuery <string>("SELECT TOP 1 SettingValue FROM SiteSettings WHERE SettingName = '" + settingName + "'").FirstOrDefault(); return(settingValue); } } else if (dbName.ToLower() == "pmm") { using (AppPMMEntities Db = new AppPMMEntities()) { var settingValue = Db.Database.SqlQuery <string>("SELECT TOP 1 SettingValue FROM SiteSettings WHERE SettingName = '" + settingName + "'").FirstOrDefault(); return(settingValue); } } return(""); }
private void GetPoolMemberStats(AppPMMEntities Db, int f5PoolId, string poolName, string deviceName) { var responseContent = ""; try { ICR icr = new ICR(ApiAccount, ApiPassword); string resource = "/mgmt/tm/ltm/pool/~Common~" + poolName + "/members/stats"; List <PoolMemberInfoForWeb> poolMembers = new List <PoolMemberInfoForWeb>(); JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }; IRestResponse response = icr.EstablishConnection(resource, deviceName); responseContent = response.Content; if (responseContent.Contains("nestedStats")) { responseContent = responseContent.Replace("connq.ageEdm", "connqageEdm"); responseContent = responseContent.Replace("connq.ageEma", "connqageEma"); responseContent = responseContent.Replace("connq.ageHead", "connqageHead"); responseContent = responseContent.Replace("connq.ageMax", "connqageMax"); responseContent = responseContent.Replace("connq.depth", "connqdepth"); responseContent = responseContent.Replace("connq.serviced", "connqserviced"); responseContent = responseContent.Replace("serverside.bitsIn", "serversidebitsIn"); responseContent = responseContent.Replace("serverside.bitsOut", "serversidebitsOut"); responseContent = responseContent.Replace("serverside.curConns", "serversidecurConns"); responseContent = responseContent.Replace("serverside.maxConns", "serversidemaxConns"); responseContent = responseContent.Replace("serverside.pktsIn", "serversidepktsIn"); responseContent = responseContent.Replace("serverside.pktsOut", "serversidepktsOut"); responseContent = responseContent.Replace("serverside.totConns", "serversidetotConns"); responseContent = responseContent.Replace("status.availabilityState", "statusavailabilityState"); responseContent = responseContent.Replace("status.enabledState", "statusenabledState"); responseContent = responseContent.Replace("status.statusReason", "statusstatusReason"); responseContent = responseContent.Replace("/Common/", ""); responseContent = responseContent.Replace("~Common~", ""); var data = JsonConvert.DeserializeObject <dynamic>(responseContent, settings); foreach (var server in data.entries) { PoolMemberInfoForWeb poolMember = new PoolMemberInfoForWeb(); poolMember.deviceName = deviceName; poolMember.poolName = poolName; poolMember.addr = server.Value.nestedStats.entries.addr.description.Value.ToString(); poolMember.connqageEdm = server.Value.nestedStats.entries.connqageEdm.value.Value.ToString(); poolMember.connqageEma = server.Value.nestedStats.entries.connqageEma.value.Value.ToString(); poolMember.connqageHead = server.Value.nestedStats.entries.connqageHead.value.Value.ToString(); poolMember.connqageMax = server.Value.nestedStats.entries.connqageMax.value.Value.ToString(); poolMember.connqdepth = server.Value.nestedStats.entries.connqdepth.value.Value.ToString(); poolMember.connqserviced = server.Value.nestedStats.entries.connqserviced.value.Value.ToString(); poolMember.curSessions = server.Value.nestedStats.entries.curSessions.value.Value.ToString(); poolMember.monitorRule = server.Value.nestedStats.entries.monitorRule.description.Value; poolMember.monitorStatus = server.Value.nestedStats.entries.monitorStatus.description.Value.ToString(); poolMember.nodeName = server.Value.nestedStats.entries.nodeName.description.Value.ToString(); poolMember.port = server.Value.nestedStats.entries.port.value.Value.ToString(); poolMember.serversidebitsIn = server.Value.nestedStats.entries.serversidebitsIn.value.Value.ToString(); poolMember.serversidebitsOut = server.Value.nestedStats.entries.serversidebitsOut.value.Value.ToString(); poolMember.serversidecurConns = server.Value.nestedStats.entries.serversidecurConns.value.Value.ToString(); poolMember.serversidemaxConns = server.Value.nestedStats.entries.serversidemaxConns.value.Value.ToString(); poolMember.serversidepktsIn = server.Value.nestedStats.entries.serversidepktsIn.value.Value.ToString(); poolMember.serversidepktsOut = server.Value.nestedStats.entries.serversidepktsOut.value.Value.ToString(); poolMember.serversidetotConns = server.Value.nestedStats.entries.serversidetotConns.value.Value.ToString(); poolMember.sessionStatus = server.Value.nestedStats.entries.sessionStatus.description.Value.ToString(); poolMember.statusavailabilityState = server.Value.nestedStats.entries.statusavailabilityState.description.Value.ToString(); poolMember.statusenabledState = server.Value.nestedStats.entries.statusenabledState.description.Value.ToString(); poolMember.statusstatusReason = server.Value.nestedStats.entries.statusstatusReason.description.Value.ToString(); poolMember.totRequests = server.Value.nestedStats.entries.totRequests.value.Value.ToString(); poolMember.F5PoolId = f5PoolId; poolMembers.Add(poolMember); } if (poolMembers.Count > 0) { Db.PoolMemberInfoForWebs.AddRange(poolMembers); Db.SaveChanges(); } } } catch (Exception ex) { Helper.LogError(ex.Message + "\r\n" + responseContent + "\r\n"); } }
public string CreateReport(AppPMMEntities Db) { var responseContent = ""; try { // generate html StringBuilder sb = new StringBuilder(); sb.AppendLine("<center>"); sb.AppendLine("<table border='1'>"); var deviceName = ""; var shortPoolName = ""; var poolName = ""; var f5Pools_ = Db.F5Pool.Where(w => w.Name.ToUpper().Contains("EIDM")).OrderBy(o => o.DeviceName).ToList(); var f5Pools = (from a in f5Pools_ join b in Db.MasterDeviceLists on a.DeviceName equals b.pairName into aa from bb in aa.DefaultIfEmpty() select new { a, DeviceIp = (bb == null) ? "" : bb.mgmtIP }).ToList(); foreach (var f5Pool in f5Pools) { if (deviceName != f5Pool.a.DeviceName) { // device header sb.AppendLine("<tr>"); sb.AppendLine("<td style='background-color:#80bfff;color:#00004d;text-align:center;font-weight:bold;font-family:arial;padding:4px;font-size:1.1em;' colspan='8'>"); sb.AppendLine(f5Pool.a.DeviceName + ".rdcms.eds.com"); sb.AppendLine("</td>"); sb.AppendLine("</tr>"); deviceName = f5Pool.a.DeviceName; } // pool header poolName = f5Pool.a.Name.ToLower(); shortPoolName = f5Pool.a.Name; if (poolName.Contains("test") || poolName.Contains("dev")) { shortPoolName = "EIDM Dev/Test"; } else if (poolName.Contains("prod")) { shortPoolName = "EIDM Production"; } else if (poolName.Contains("imp")) { shortPoolName = "EIDM Implementation"; } sb.AppendLine("<tr>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;white-space:nowrap;' nowrap>" + f5Pool.a.DeviceName + " - " + shortPoolName + "</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Status</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>VIP IP</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>RD</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Port</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>SNAT</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>SNAT Pool</td>"); sb.AppendLine("<td style='background-color:#235A7D;color:#ffffff;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>rules</td>"); sb.AppendLine("</tr>"); // pool header II sb.AppendLine("<tr>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>" + poolName.Replace("pool_", "vs_") + "</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>" + f5Pool.a.StatusAvailabilityState + "</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>" + f5Pool.DeviceIp + "</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>?RD</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>?Port</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>?SNAT</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>?SNAT Pool</td>"); sb.AppendLine("<td style='background-color:#CFD5F9;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>?rules</td>"); sb.AppendLine("</tr>"); // members if (f5Pool.a.PoolMemberInfoForWebs.Count > 0) { sb.AppendLine("<tr valign='top'>"); sb.AppendLine("<td style='background-color:#cceeff;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;white-space:nowrap;' rowspan='" + (f5Pool.a.PoolMemberInfoForWebs.Count + 2) + "' valign='top' nowrap>Pool Name: " + poolName + "</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Server Name</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>IP Address</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>RD</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Port</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Monitor</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>State</td>"); sb.AppendLine("<td style='background-color:#878CAB;color:#0E2838;font-weight:bold;font-family:arial;padding:3px;font-size:.9em;'>Server Session</td>"); sb.AppendLine("</tr>"); var backgroundColor = ""; foreach (var member in f5Pool.a.PoolMemberInfoForWebs) { backgroundColor = "#cceeff"; if (member.monitorStatus == "down") { backgroundColor = "#FA6359"; } sb.AppendLine("<tr>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>" + member.nodeName + "</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>" + member.addr + "</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>RD</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>" + member.port + "</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>?Monitor</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>" + member.monitorStatus + "</td>"); sb.AppendLine("<td style='background-color:" + backgroundColor + ";color:#0E2838;font-family:arial;padding:3px;font-size:.9em;'>monitor-" + member.sessionStatus + "</td>"); sb.AppendLine("</tr>"); } } } sb.AppendLine("</table>"); sb.AppendLine("</center>"); var html = sb.ToString(); return(html); // generate html file //using (StreamWriter outfile = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\document.html")) //{ // outfile.Write(html); //} } catch (Exception ex) { Helper.LogError(ex.Message + "\r\n" + responseContent + "\r\n"); } return(""); }