Forum Discussion

sogboj_312474's avatar
sogboj_312474
Icon for Nimbostratus rankNimbostratus
Dec 22, 2018

Is there a way in an iRule to determine if an ASM policy exists before doing an ASM::enable on it?

I am trying to base the ASM policy i assign to my inbound connections on the URL in my iRule. If i do an ASM::enable on a policy that does not yet exist the connection/session fails.

 

Is there a way to check if the ASM policy exists before doing an enable? Something like:

 

if { [AMS::policy exists $policy] } { ASM::enable $policy }

 

1 Reply

  • KWH,

     

    It seems like what you are looking for is the iRules 'catch' statement. This will try to run a piece of code and check for any runtime errors. If there is any error, it will run a second block of code instead. This will help you check if a certain policy exists. I haven't properly tested this code, but I believe your solution should look something like this.

     

    if { [catch {
         ASM::enable $policy
         log local0. "$policy was enabled"  
         }] } then {
             This block only triggers if the above code would fail
            log local0. "$policy does not exist"
        }

    More information here, if you would like to research some more yourself.