Forum Discussion

Arden_109503's avatar
Arden_109503
Icon for Nimbostratus rankNimbostratus
Sep 27, 2011

Creating a Monitor

Hi,

 

 

Loving pycontrol, got it to create vips, pools and nodes but having trouble creating a HTTP monitor.

 

 

 

Does anyone have an example of a HTTP monitor? I'm trying to create a monitor with a send string of 'Get /200.html' and receive string of 'OK'.

 

 

 

Arden

 

3 Replies

  • Arden: Here's a working example. Lots and lots of objects to set up, then some attributes to set.

     

    
     Start setting up your types. We'll do the monitor template first.
    tmplt = m.typefactory.create('LocalLB.Monitor.MonitorTemplate')
    tmplt.template_name = 'matt_test'
    
     Create the template_type
    tmplt_type = m.typefactory.create('LocalLB.Monitor.TemplateType')
    tmplt.template_type = tmplt_type.TTYPE_HTTP
    
     Ditto Attrs, and the IPPort stuff that goes inside.
    tmplt_attrs = m.typefactory.create('LocalLB.Monitor.CommonAttributes')
    dest_ipport = m.typefactory.create('LocalLB.MonitorIPPort')
    
     Create the address type structure for the dest_ipport object.
    addr_type = m.typefactory.create('LocalLB.AddressType')
    tmplt_attrs.dest_ipport.address_type.value = addr_type.ATYPE_STAR_ADDRESS
    tmplt_attrs.dest_ipport.address_type.value = addr_type.ATYPE_STAR_ADDRESS_STAR_PORT
    
    ipport = m.typefactory.create('Common.IPPortDefinition')
    ipport.address='172.16.200.131'
    ipport.port=80
    
     Now start setting attributes.
    tmplt_attrs.parent_template='http'
    tmplt_attrs.interval=5
    tmplt_attrs.timeout=16
    tmplt_attrs.is_directly_usable=True
    tmplt_attrs.is_read_only=False
    tmplt_attrs.dest_ipport.ipport = ipport
    
     Whew! Now create :)
    m.create_template(templates=[tmplt],template_attributes=[tmplt_attrs])
    

     

    When you're done with your code, this would be a good code share sample 🙂

     

     

    --Matt Cauthorn
  • Awesome, worked great!

     

     

    I used:

     

    send_string = m.typefactory.create('LocalLB.Monitor.StringValue')

     

    send_string.type="STYPE_SEND"

     

    send_string.value="GET /200.html"

     

     

    recv_string = m.typefactory.create('LocalLB.Monitor.StringValue')

     

    recv_string.type="STYPE_RECEIVE"

     

    recv_string.value="OK"

     

     

     

    Whew! Now create :)

     

    m.create_template(templates=[tmplt],template_attributes=[tmplt_attrs])

     

    m.set_template_string_property(['matt_test'],[send_string])

     

    m.set_template_string_property(['matt_test'],[recv_string])

     

     

    To set the Send and Recieve strings.
  • Hi,

     

     

    you could sent them in one call by invoking it like that :

     

     

    m.set_template_string_property([name,name],[send_string,recv_string])