Forum Discussion

keegan_morrison's avatar
keegan_morrison
Icon for Nimbostratus rankNimbostratus
Jun 09, 2008

Generating IPPortDefinition in php

Hi. I'm stuck on something that seems so simple, yet has befuddled me for quite some time. Im trying to use LocalLB.PoolMember.wsdl to get statistics (specifically current connections) of a specific node. As far as i know, this is the only way to get stats for a specific node and port, if not please let me know.

Anywho, I'm doing it like this (php5):

  
  $wdsl = "LocalLB.PoolMember.wsdl";  
  $params['pool_names'][] = $pool;  
  $addrs = Array(  
                   'address' => '10.93.66.167',  
                   'port' => 80  
                 );  
  $params['members'] = $addrs;  
  

Here is what this array looks like:

  
  Array  
  (  
      [pool_names] => Array  
          (  
              [0] => dsweb_tolphp5_pool  
          )  
    
      [members] => Array  
          (  
              [address] => 10.93.66.167  
              [port] => 80  
          )  
    
  )  
  

And here is the output when i call get_statistics():

  
  Array  
  (  
      [0] => stdClass Object  
          (  
              [statistics] =>   
              [time_stamp] => stdClass Object  
                  (  
                      [year] => 2008  
                      [month] => 6  
                      [day] => 9  
                      [hour] => 21  
                      [minute] => 3  
                      [second] => 46  
                  )  
          )  
  )  
  

If i try to rearrange things, it complains about not being able to find parameter 'address'. I have the correct partition selected, a valid pool, and valid IP/port in that pool for this query.

So, why am i not getting back statistics? I'm guessing its because im not defining my members array correctly. If it does look correct to you, how can i go about troubleshooting further?

7 Replies

  • Patrick_Chang_7's avatar
    Patrick_Chang_7
    Historic F5 Account
    get_statistics requires an array of strings (the list of pool names - in your case, just one), and a 2 dimensional array of pool members (members per pool).
  • Posted By pchang on 06/09/2008 7:03 PM

     

     

    get_statistics requires an array of strings (the list of pool names - in your case, just one), and a 2 dimensional array of pool members (members per pool).

     

     

     

    Right, i understand that to be the case from the documentation. What i'm asking is what the structure of the 2 dimensional array should be. I don't necessarily needa code example, just an example of the array would be fine.
  • I specifically haven't answered this one because I have zero experience working with PHP and especially the SOAP interface so I didn't want to mislead you.

     

     

    From your first response, you did get back a timestamp so are you sure there is nothing in the statistics array returned? Is it zero length? The MemberStatistics array returned contains multiple MemberStatistics structures for each requested pool member. In each MemberStatistic structure, there is a MemberStatisticEntry array (the statistics variable you are displaying). This is not a scalar but an array of statistics for each member and an embedded list of statistics.

     

     

    Did you verify that the MemberStatistics[0].statistics array was indeed empty?

     

     

    A SOAP trace would help out, is that something the php toolkit can do?

     

     

    If it is indeed an empty array, then you are not correctly serializing the 2-d array for the members parameter in the get_statistics() method.

     

     

    Oh, and if you could provide the actual code where you are making the method call? It's hard to tell what you are passing in.

     

     

    I can provide you samples in perl, .Net, or PowerShell relatively easily if that will help.

     

     

    -Joe
  • Don_MacVittie_1's avatar
    Don_MacVittie_1
    Historic F5 Account
    Here's what I think you're looking for Keegan:

     

     

    [members] => Array

     

    (

     

    Array

     

    (

     

    [address] => 10.93.66.167

     

    [port] => 80

     

    )

     

    )

     

     

    I haven't tested this, but it should be an array of arrays of pool members.

     

     

    Don.
  • Posted By dmacvittie on 06/19/2008 2:25 PM

     

     

    Here's what I think you're looking for Keegan:

     

     

    [members] => Array

     

    (

     

    Array

     

    (

     

    [address] => 10.93.66.167

     

    [port] => 80

     

    )

     

    )

     

     

    I haven't tested this, but it should be an array of arrays of pool members.

     

     

    Don.

     

     

     

     

    Thanks for your response, dmacvittie. When i try to make members an array of arrays of addresses/ports, i get an error message stating "an error occurred in the call: Could not find element by name: address". However, when i make members just one array defined as

     

    $members = Array('address'=>'10.93.67.167', port=>'80');
    like I did in my original post, i do not get that error. It still does not work, however.

     

     

     

    Joe, thanks for your response as well. The method I used for displaying the soap response is a PHP built in, called print_r(). Essentially, it dumps all elements of an array, including any nested arrays. I tried accessing the statistics array directly, and it was empty.

     

     

    I was able to do a soap trace. I'm not sure exactly what it is supposed to look like. For troubleshooting purposes, I will post my full code as well as the output, including the soap trace.

     

     

      
      $wdsl = "LocalLB.PoolMember.wsdl";  
      $soapoptions = array('namespace' => 'urn:iControl', 'trace' => 1);  
        
      $params['pool_names'] = Array(0 => "dsweb_tolphp5_pool");  
        
      $params['members'] = Array(  
              'address' => '10.93.66.167',  
              'port' => 80);  
        
      //here is where dmacvittie suggested making the members array an array of arrays,   
      //however, that causes the error message above.  
        
        
      print_r($params);  
        
      //$this->proxy_parms just has my username & password, i know that works fine.  
      $client = new SOAP_Client($this->wsdl_url . $wdsl, true, '', $this->proxy_parms);  
      $client->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);  
      $client->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);  
        
      $response  = $client->call('get_statistics', $params, $this->soapoptions);  
        
        
        
      if (PEAR::isError($response))  
      {  
            die( "an error occurred in the call " . $response->message );  
      }  
      print_r($response);  
        
      //output soap trace  
      echo $client->__getLastRequest();  
      

     

     

    If any part of that is confusing, I can provide an explanation.

     

     

    The output regarding the arrays & responses hasn't changed since my first post. Here is the soap trace output:

     

     

      
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
       xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  
       xmlns:ns4="urn:iControl"  
       xmlns:ns5="urn:iControl:LocalLB/PoolMember"  
       SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">  
        
        
        
        
      dsweb_tolphp5_pool  
        
        
      10.93.66.167  
      80  
        
        
      

     

     

    I'm not sure what that is supposed to look like. However, I do notice that the declaration for the port value is an int, and the documentation calls for a long. Could that be causing the problem?

     

     

    I have noticed that changing the IP to a node address that isn't in that pool makes no difference. Smae thing for changing the pool_names value, if I change it to a pool name that isn't in the currently selected partition, nothing special happens, i just get the response from my original post. I suspect this might be an issue. In most other instances, if I ask for information regarding a pool that is not a member of my current partition, it returns an error message. Could be a red herring, could be useful.

     

     

    Let me know if you require any further information, and thanks for the help.
  • Not sure if you are still having the problem, or if you came up with another way to fix the problem, but I had a similar problem while trying to create pools using php. I had to wrap the entire sequence in an array to get it to work:

     
     $p['pool1'] = array(array(array('address'=>'192.168.1.1','port'=>80))); 
     $p['pool2'] = array(array(array('address'=>'192.168.1.2','port'=>80))); 
      
     foreach ($p as $k => $v) { 
     try { 
     $client->create(array($k),array(0),$v); 
     } catch (Exception $e) { 
     echo $e->getMessage(); 
     } 
     } 
     

    so the "IPPortDefinition[][]" parameter when you pass it to the soapclient looks like:

     
     Array 
     ( 
         [0] => Array 
             ( 
                 [0] => Array 
                     ( 
                         [address] => 192.168.1.1 
                         [port] => 80 
                     ) 
      
             ) 
      
     )