Forum Discussion
Simple "Hello World" iRule
Here's the iRule I tried:
when HTTP_REQUEST {
if { [HTTP::uri] eq "/mytest" } {
set response "Hello World"
HTTP::respond 200 content $response "Content-Type" "text/xml"
}
}
To see if it's working, I've tried the following URLs:
http://[ip]/mytest
https://[ip]/mytest
Neither of the URLs seem to do what I want them to do, which is to simply display "Hello World." Am I doing something wrong, or is my problem in some other configuration in my F5?
Thanks!
7 Replies
- bmw_10782
Nimbostratus
Hi Scott,
The iRule is well written. And you should have a Hello World( not a well formatted xml output, but at least you should have it)
Have you configured the VS with this iRule?
Try to add a log
when HTTP_REQUEST {
if { [HTTP::uri] eq "/mytest" } {
set response "Hello World"
log local0. $response
HTTP::respond 200 content $response "Content-Type" "text/xml"
}
}
or something like this :)
Ps: you can avoid using the response variable : HTTP::respond 200 content "Hello World" "Content-Type" "text/xml" - Scott_82463
Nimbostratus
bmw,Thanks for the quick response!
I changed my iRule to the following:
when HTTP_REQUEST {
if { [HTTP::uri] eq "/mytest" } {
log local0. "Hello World"
HTTP::respond 200 content "Hello World" "Content-Type" "text/xml"
}
}
I added it in with the xui iRule utility, so as far as I know it should be up and running. However, I still don't seem to be getting any response. Does the log local0 line write to /var/log/ltm, or is the default location somewhere else? Also, am I calling the URL correctly to trigger this rule?
Thanks!
- Michael_Yates
Nimbostratus
Worked fine for me:
Invalid at the top level of the document. Error processing resource 'http://test.domain.com/mytest'. Line 1, Position 1
Hello World
^
With your "eq" if you have anything else (including a trailing slash, the it will not qualify). You could use starts_with instead and see if you get it to work for you.
The "log local0." will log to the /var/log/ltm. You are calling it correctly in your iRule. - Scott_82463
Nimbostratus
I'm starting to think HTTP_REQUEST isn't configured properly on my F5. I just tried the following iRule:when HTTP_REQUEST {
log local0. "Hello"
}
Nothing is getting written to /var/log/ltm no matter what URL I call. Is there something you have to do to turn an iRule on after you add it to the list? If not, does anyone know why HTTP_REQUEST might not be working?
Thanks!
- hoolio
Cirrostratus
Hi Scott,
How are you making the HTTP request? Can you try this iRule:when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: Connected to [virtual name] [IP::local_addr]:[TCP::local_port]" HTTP::respond 200 content "Connected to [virtual name] [IP::local_addr]:[TCP::local_port] from [IP::client_addr]:[TCP::client_port]" }
Then start with a curl request on the LTM command line:
curl -v http://1.1.1.1
where 1.1.1.1 is the virtual server address. If that works, then try from a browser. If the curl command works but you don't see a response from the iRule in a browser, then it's likely the request isn't making it to LTM.
Aaron - Scott_82463
Nimbostratus
The curl command doesn't seem to be working for me, here's what it returned:* About to connect() to [ip] port 80
* Trying [ip]... Connection refused
* couldn't connect to host
* Closing connection 0
curl: (7) couldn't connect to host
So I'm assuming this means that there's a problem with my F5 rather than my iRules. I'll have to look into this. Thanks for the help everyone!
- hoolio
Cirrostratus
Do you have ARP enabled on the virtual server address (Local Traffic ›› Virtual Address List)? Is the virtual server enabled?
Aaron
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com