/// <summary> /// This Method communicates with the F5 and returns the member list for a specified Pool, and adds a new Pool /// </summary> /// <param name="poolName">The name of the Pool we are querying the member list of</param> /// <returns>A F5 Pool Member List, containing all the members of a specified Pool</returns> public List <F5LBPoolMember> GetLBPoolMembers(string poolName) { // Create a list of F5 Pools Member Objects List <F5LBPoolMember> F5PoolMembers = new List <F5LBPoolMember>(); if (isF5Connected) { // Query the F5 for the Session State and Monitor State of the Members in this pool LocalLBPoolMemberMemberSessionState[][] bigIPPoolMemberState = Connection.LocalLBPoolMember.get_session_enabled_state(new string[] { poolName }); LocalLBPoolMemberMemberMonitorStatus[][] bigIPPoolMemberMonitor = Connection.LocalLBPoolMember.get_monitor_status(new string[] { poolName }); // Now, loop trough the Elements in the Array, 1 per Pool Member, and update the Pool Member Object each time with the information we have. for (int i = 0; i < bigIPPoolMemberState[0].Length; i++) { F5LBPoolMember memberState = new F5LBPoolMember(poolName, bigIPPoolMemberState[0][i].member, ""); memberState.state = CalculateNodeState(bigIPPoolMemberMonitor[0][i].monitor_status, bigIPPoolMemberState[0][i].session_state); memberState.activeConnections = this.GetLBPoolMemberActiveConnections(poolName, bigIPPoolMemberState[0][i].member.address + ":" + bigIPPoolMemberState[0][i].member.port); // Add the member and its details into the object list. F5PoolMembers.Add(memberState); } } else { throw new Exception("We are not connected to the F5!"); } return(F5PoolMembers); }
/// <summary> /// This Method communicates with the F5, and let us search for virtual servers /// </summary> /// <param name="query">The patern we are expecting the query string, is the same format which we would expect if they /// user was to provide the name of a member, ie. "address:port", however in order to make this smart, we will accept "*:*" /// or a diritive of the pattern</param> /// <returns>Pool Member List, Identifying the matched Virtual Servers</returns> public List <F5LBPoolMember> LookupLBVirtualServer(string query) { // The patern we are expecting the query string, is the same format which we would expect if they // user was to provide the name of a member, ie. address:port // however, in order to make this smart, we will accept *:* or a diritive of the patter // Lets begin assuming the query will be for ALL Members and Port string queryAddress = "*"; string queryPort = "*"; // Now, lets see if the user actaully asked for a port if (query != null) { queryAddress = query; String[] sSplit = query.Split(new char[] { ':' }); if (2 == sSplit.Length) { queryAddress = sSplit[0]; queryPort = sSplit[1]; } // Now after applying the split, we need to just check that we have not // ended up with assigning a null value; eg ":*" or ":" as passed in. if (queryAddress == null) { queryAddress = "*"; } ; if (queryPort == null) { queryPort = "*"; } ; } List <F5LBPoolMember> virtualMembers = new List <F5LBPoolMember>(); if (isF5Connected) { string[] virtualServers = Connection.LocalLBVirtualServer.get_list(); CommonIPPortDefinition[] members = Connection.LocalLBVirtualServer.get_destination(virtualServers); for (int i = 0; i < members.Length; i++) { if (Regex.IsMatch(members[i].address + ":" + members[i].port, query)) { F5LBPoolMember matchedMember = new F5LBPoolMember(virtualServers[i], members[i]); virtualMembers.Add(matchedMember); } } } else { throw new Exception("We are not connected to the F5!"); } return(virtualMembers); }
/// <summary> /// This Method communicates with the F5, and adds a new Pool, along with its member list and TCP Port address /// </summary> /// <param name="query">The patern we are expecting the query string, is the same format which we would expect if they /// user was to provide the name of a member, ie. "address:port", however in order to make this smart, we will accept "*:*" /// or a diritive of the pattern</param> /// <returns>Pool Member List, Identifying the matched Pool Members</returns> public List <F5LBPoolMember> LookupLBPoolMembers(string query) { // Lets begin assuming the query will be for ALL Members and Port string queryAddress = "*"; string queryPort = "*"; // Now, lets see if the user actaully asked for a port if (query != null) { queryAddress = query; String[] sSplit = query.Split(new char[] { ':' }); if (2 == sSplit.Length) { queryAddress = sSplit[0]; queryPort = sSplit[1]; } // Now after applying the split, we need to just check that we have not // ended up with assigning a null value; eg ":*" or ":" as passed in. if (queryAddress == null) { queryAddress = "*"; } ; if (queryPort == null) { queryPort = "*"; } ; query = queryAddress + ":" + queryPort; } List <F5LBPoolMember> virtualMembers = new List <F5LBPoolMember>(); if (isF5Connected) { string[] poolList = Connection.LocalLBPool.get_list(); CommonIPPortDefinition[][] poolMembers = Connection.LocalLBPool.get_member(poolList); for (int poolLoop = 0; poolLoop < poolList.Length; poolLoop++) { CommonIPPortDefinition[] currentPoolMember = poolMembers[poolLoop]; for (int memberLoop = 0; memberLoop < poolMembers.Length; memberLoop++) { if (Regex.IsMatch(currentPoolMember[memberLoop].address + ":" + currentPoolMember[memberLoop].port, query, RegexOptions.IgnoreCase)) { F5LBPoolMember matchedMember = new F5LBPoolMember(poolList[poolLoop], currentPoolMember[memberLoop]); virtualMembers.Add(matchedMember); } } } } else { throw new Exception("We are not connected to the F5!"); } return(virtualMembers); }