# Need help combining 2 irules

**URL:** <https://community.f5.com/t/need-help-combining-2-irules/13398>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [June 5, 2012, 5:00pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398 "2012-06-05T17:00:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Boo](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@Christopher\_Boo](https://community.f5.com/u/Christopher_Boo)\
**Post date:** [June 5, 2012, 5:00pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/1 "2012-06-05T17:00:37Z")

</div>

I’m not much of a scripter but I usually figure it out of I stare at it long enough. I’m trying to combine the 2 irules below. I’d like to insert irule 2 at the end of irule 1. The idea is to allow anyone on the network to hit the specified URIs and be directed to the rec.utt.pool, but to only allow internal users (api.network.list class) to go to the api.utt.pool and either drop or provide an http access denied message to everyone else. I’d appreciate any help.

Thanks,

Chris

Irule 1

when HTTP\_REQUEST {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

pool api.utt.pool

}

}

}

Irule 2

when CLIENT\_ACCEPTED {

if { [class match [IP::client\_addr] equals api.network.list] } {

pool api.utt.pool

} else {

drop

}

---

<div class="post-metadata">

**Author:** ![Christopher\_Boo](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@Christopher\_Boo](https://community.f5.com/u/Christopher_Boo)\
**Post date:** [June 5, 2012, 7:02pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/2 "2012-06-05T19:02:23Z")

</div>

I’m now down to 1 error.

error: line 10: [undefined procedure: else] [else]

when HTTP\_REQUEST {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

} elseif { [class match [IP::client\_addr] equals api.network.list] } {

pool api.utt.pool

} else {

discard

}

}

}

---

<div class="post-metadata">

**Author:** ![nathe](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@nathe](https://community.f5.com/u/nathe)\
**Post date:** [June 6, 2012, 10:05am UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/3 "2012-06-06T10:05:10Z")

</div>

Christopher,

elseif needs an if so I’d say that was the issue. Try changing elseif to if and you shouldn’t need an else either.

Hope this helps.

N

---

<div class="post-metadata">

**Author:** ![Christopher\_Boo](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@Christopher\_Boo](https://community.f5.com/u/Christopher_Boo)\
**Post date:** [June 6, 2012, 12:59pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/4 "2012-06-06T12:59:17Z")

</div>

Thanks! I tried that and it still gave me an error. I’ve removed the default bit at the end of the first irule and put an else discard at the end of the second irule. This at least has me functional, though still using 2 irules.

Chris

---

<div class="post-metadata">

**Author:** ![Richard\_Harlan](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@Richard\_Harlan](https://community.f5.com/u/Richard_Harlan)\
**Post date:** [June 6, 2012, 1:06pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/5 "2012-06-06T13:06:49Z")

</div>

Try the following I changed it up a little

First I check the IP address, if match send to pool and drop out of the iRule. If not match fall through to the switch statement. If there is no match send a reset and move on.

when HTTP\_REQUEST {

if { [class match [IP::client\_addr] equals api.network.list] } {

pool api.utt.pool

return

}

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

reject

}

}

}

---

<div class="post-metadata">

**Author:** ![Christopher\_Boo](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@Christopher\_Boo](https://community.f5.com/u/Christopher_Boo)\
**Post date:** [June 6, 2012, 1:14pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/6 "2012-06-06T13:14:35Z")

</div>

The problem with this is I want the users on the api.network.list to have access to those URIs for the rec.utt.pool as well. Thanks for the input!

Chris

---

<div class="post-metadata">

**Author:** ![Richard\_Harlan](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@Richard\_Harlan](https://community.f5.com/u/Richard_Harlan)\
**Post date:** [June 6, 2012, 2:27pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/7 "2012-06-06T14:27:54Z")

</div>

Ok it then this should work I had to double the switch statement but it allows if the ip matches and the URI matches it will goto rec.utt.pool ulse api.utt.pool

when HTTP\_REQUEST {

if { [class match [IP::client\_addr] equals api.network.list] } {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

pool api.utt.pool

}

}

} else {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

reject

}

}

}

---

<div class="post-metadata">

**Author:** ![nathe](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@nathe](https://community.f5.com/u/nathe)\
**Post date:** [June 6, 2012, 2:33pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/8 "2012-06-06T14:33:12Z")

</div>

Just refreshed the screen to post my suggestion and Richard had beaten me to it 😉

Think a curly brace is missing. Here’s mine anyway:

when HTTP\_REQUEST {

if { [class match [IP::client\_addr] eq api.network.list] } {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

pool api.utt.pool

}

}

}

if { [class match [IP::client\_addr] ne api.network.list] } {

switch -glob [string tolower [HTTP::uri]] {

“/pss-alerts\*” -

“/pss-forms\*” -

“/pss-reports\*” -

“/pss-messaging\*” {

pool rec.utt.pool

}

default {

reject

}

}

}

}

At least we’re both on the same page!

N

---

<div class="post-metadata">

**Author:** ![Christopher\_Boo](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@Christopher\_Boo](https://community.f5.com/u/Christopher_Boo)\
**Post date:** [June 6, 2012, 2:50pm UTC](https://community.f5.com/t/need-help-combining-2-irules/13398/9 "2012-06-06T14:50:35Z")

</div>

That sure looks like it will do the trick. Thanks so much to both of you!

Chris
