Forum Discussion

Alex_Chan_88951's avatar
Alex_Chan_88951
Icon for Nimbostratus rankNimbostratus
Jul 21, 2008

Add data in the class

I have create a class "rate_limit_black_list" in the gui, this class store the black list host. But when i cannot use irule to insert data in the group. is my irule syntax problem or what makes me cannot do that ? thanks.

I have add "1.1.1.1" in the class, so "tested" can print in the log. And when the office ip match the client ip all statement is processed, I can see "office ip black listed" in the log and the the web page show collectly. Just the lappend that statement not working, please help.....thanks.

 
 when HTTP_REQUEST { 
 set client_ip [IP::remote_addr] 
 set office_ip "xxx.xxx.xxx.xxx" 
 set test "1.1.1.1" 
  
 if {[matchclass $test equals $::rate_limit_black_list]}{ 
 log local0.info "tested" 
 } 
  
 if { $office_ip == $client_ip }{ 
 lappend "$client_ip\n" $::rate_limit_black_list 
 log local0.info "office ip black listed" 
 pool http_01 
  
 } 
 } 
 

5 Replies

  • Hi,

     

     

    I don't think you can add data in datagroup.

     

     

    You can do this if you manipulate your class in an array. Here is an example: Click here
  • I thought you could add to a datagroup with lappend, but the change couldn't be saved to file and wouldn't be persisted through a reload of the configuration. I don't remember the exact details from the last time this came up and couldn't find the post I was thinking of.

     

     

    nmenant's right though, an array would be better to handle this. The downside is that if the config is reloaded or a new unit goes active, the existing data would be lost.

     

     

    If you need to make permanent changes to a datagroup, you'd need to use an iControl app to do this. It might be tricky though trying to take data generated from an iRule and use that as input for an iControl script.

     

     

    Aaron
  • Hi,

     

     

    I'm not sure it's possible but i never really tried to add dynamically data to a dataclass so...

     

     

    If you wanted to use a datagroup and update it remotely i would suggest an external class.

     

     

    This way you can create an iControl script that will update the file remotely. The only issue i see is that to reload the updated class you will need to reload the configuration (it doesn't work anymore to update an iRule with a space to reload the datagroup at the same time, they work on it tough since they don't consider it as a normal behavior)

     

     

    If you are interested in this application i can share it with you. I should put it on Devcentral anyway ...

     

     

    Nicolas
  • Thx all of your help, I am totally unerstand how the class and data group work, thx all you guy....^^
  • Is there a compelling reason changes can't be saved from memory to file from an iRule? In theory you could run a cronjob to modify the class from outside the rule using 'b class CLASS_NAME...', and/or save the config running in memory to file using 'b config save'. I'm wondering if it's opening a can of worms or more plausible.

     

     

    If it's not realistic to ever be able to persist changes to a class from an iRule, is there a recommended way of triggering an iControl script based on a change in state of an iRule?

     

     

    Thanks,

     

    Aaron