Example #1
0
function f5_pool_member_states($lb, $pool_list, $hosts_map, $username, $password)
{
    $wsdl_poolmember = "https://{$lb}/iControl/iControlPortal.cgi?WSDL=LocalLB.PoolMember";
    $location = "https://{$lb}/iControl/iControlPortal.cgi?";
    $client = new SoapClient($wsdl_poolmember, array('location' => $location, 'login' => $username, 'password' => $password));
    $memberlist = $client->get_object_status($pool_list);
    foreach ($pool_list as $index => $pool) {
        # Loop through each pool member to find out the number of active
        # connections. You could possibly get rid of this if you don't
        # care for this info.
        foreach ($memberlist[$index] as $member_index => $member_value) {
            $ip = $member_value->member->address;
            $port = $member_value->member->port;
            $availability_status = $member_value->object_status->availability_status;
            $enabled_status = $member_value->object_status->enabled_status;
            switch ($availability_status) {
                case "AVAILABILITY_STATUS_GREEN":
                    if ($enabled_status == "ENABLED_STATUS_ENABLED") {
                        $status = "enabled";
                    } else {
                        $status = "disabled";
                    }
                    break;
                case "AVAILABILITY_STATUS_RED":
                    if ($enabled_status == "ENABLED_STATUS_ENABLED") {
                        $status = "offline";
                    } else {
                        $status = "forced_offline";
                    }
                    break;
            }
            $request->address = $ip;
            $request->port = $port;
            /* Don't ask why we have to wrap it in two arrays but we do */
            $full_request = array(array($request));
            $result = $client->get_statistics($pool_list, $full_request);
            $curr_connections = $result[0]->statistics[0]->statistics[4]->value->low;
            unset($full_request);
            /* convert IP address as shown in F5 into a host name */
            $address = f5_convert_ip_to_hostname($ip, $hosts_map);
            if ($address === false) {
                $address = $ip;
            }
            $pool_states[] = array("server_name" => $address, "port" => $port, "status" => $status, "curr_connections" => $curr_connections);
        }
    }
    return $pool_states;
}