Forum Discussion
iRule to ping host
I'm pretty new to the Big IP load balancers. We have a couple servers on which we have SharePoint sites load balanced. The load balancing appears to work fine. Obviously, I've set up a Virtual Server with a virtual IP, so when users connect to a site, for instance sitename.domain.net, they will connect to the IP of the virtual server and get load balanced. However, we talked about being able to ping the sitename.domain.net from a specific workstation and getting the IP address of the member server to whichthe specific workstation is connected currently to aid in troubleshooting, instead of the IP of the Virtual Server configured on the load balancer. The SharePoint admins say they saw this when we initially set up the Virtual Server, and I've not made any changes on the load balancer since. We did make some DNS tweaks, but I don't see where this would have enabled them to tell which member a specific workstation is connected to. I'm thinking we could set up an iRule for this, but again I'm new to the F5. Any ideas? Maybe there is an easier way? Thanks.
33 Replies
- What_Lies_Bene1
Cirrostratus
LiveHTTPHeaders for Firefox is just an add-in install so probably your best bet.
The iRule needs to be assigned to specific Virtual Servers so you can decide which will log or won't.
It's too early to log the selected Pool Member in the CLIENT_ACCEPTED event. How about this (but test carefully, this could overwhelm your device if the connection count is high);when LB_SELECTED { log local0. "Client [IP::addr [IP::client_addr] connected to real server IP: [LB::server addr]" } - Darthw_20046
Nimbostratus
Thanks Steve. Would the format be more like this though? I think there's some extra around the Client IP part as the iRules errored when I tried to set one up.
when LB_SELECTED {
log local0. "Client IP:[IP::client_addr] connected to real server IP: [LB::server addr]"
}
Also, just for my learning, when you say "It's too early to log the selected Pool Member in the CLIENT_ACCEPTED event." So the "CLIENT ACCEPTED" event is simply tied to the Load Balancer accepting the connection from the client, and at that point the LB has not yet connected the client to a member of the pool to determine a destination host IP? And I see where to assign the iRule to the Virtual Servers now, which for some reason I overlooked before. - Mohamed_Lrhazi
Altocumulus
For troubelshooting and debugging, inserting a header in evey resposne is the best option. The devoloper can tell directly, frrom his Firefox, which server is bahaving differently, without the need to inspect logs and trying to correlate his requests
amongst potentially thousands others happening at the same time.
I do this on one of my sites and I dont insert the actual backend server IP, pool name and so on, but just code that we can easly decode back.
Thanks,
Mohamed. - What_Lies_Bene1
Cirrostratus
The original iRule is correct although your version might still work.
Yes, you are correct regarding the events. - Darthw_20046
Nimbostratus
When I try to save the iRule as it is written I get this on the Load Balancer:
error: line 2: [parse error: missing close-bracket] [[IP::addr [IP::client_addr] connected to real server IP: [LB::server addr]" ]
It's set up like this in the LB. Am I missing something in the format?
when LB_SELECTED {
log local0. "Client [IP::addr [IP::client_addr] connected to real server IP: [LB::server addr]"
}
To change it I simply took out the "[IP::addr ", and changed it to "IP" and it seemed to save without error. Again, I'm new, so I'm not sure which format is ultimately correct. Thanks.
when LB_SELECTED {
log local0. "Client IP:[IP::client_addr] connected to real server IP: [LB::server addr]"
} - Mohamed_Lrhazi
Altocumulus
Your last code is correct.
Think of it this way (for more details google for TCL tutorials) :
you are callling a "function" called "log"
passing it two arguments, "local0." and a string.
The sting contains "expressions", the stuff between [], which are executed and replaced with the result of the expressions.
Your two expressions inside the string above are calls to the following functions:
https://devcentral.f5.com/wiki/irules.IP__client_addr.ashx
https://devcentral.f5.com/wiki/irules.LB__server.ashx
Thanks,
Mohamed. - Darthw_20046
Nimbostratus
The logging of the Client IP is working with this code below, thanks Mohamed and Steve. However, it seems I can't give the Sharepoint admins access to view the logs on the Big IP without giving them administrator access to the device, which I don't want to do.
when LB_SELECTED {
log local0. "Client IP:[IP::client_addr] connected to real server IP: [LB::server addr]"
}
So, I've been working on the HTTP header as Steve suggested, so they could use HTTPWatch, even Wireshark, to review the HTTP headers from response to seek the IP address of the member of the pool to which the client connected. However, I get syntax errors trying to save the code below as an iRule, and when I try to tweak it myself to where I finally get the iRule to save without error, when I try to connect to the Sharepoint site I basically get "the website cannot be found" in Internet Explorer. Once I remove the iRule I can hit the site. So, I'm not sure what I need to adjust so that I can get the IP address of the member server to which the client connected without using the logfiles on the Big IP. I'd like to set up something that the Sharepoint admins can access to review without giving them Admin access to the BigIP. I know the sharepoint servers that are members of the pool have IIS logs that will show the IP address of the connecting client, but in this case the IIS logs just show the IP address of the load balancer, rather than the client workstation, so even if there is a way to pass the Client IP through without messing with connectivity?
when LB_SELECTED {
set whichserver [LB::server addr]
}
when HTTP_REQUEST {
if { string tolower [HTTP::uri] equals "/whichserver" } {
HTTP::respond 200 content "Real server IP is: $whichserver" noserver Content-Type
"text/html" Connection "Close"
Stop processing the iRule for this event here
return }
} - Darthw_20046
Nimbostratus
The logging of the Client IP is working with this code below, thanks Mohamed and Steve. However, it seems I can't give the Sharepoint admins access to view the logs on the Big IP without giving them administrator access to the device, which I don't want to do.
when LB_SELECTED {
log local0. "Client IP:[IP::client_addr] connected to real server IP: [LB::server addr]"
}
So, I've been working on the HTTP header as Steve suggested, so they could use HTTPWatch, even Wireshark, to review the HTTP headers from response to seek the IP address of the member of the pool to which the client connected. However, I get syntax errors trying to save the code below as an iRule, and when I try to tweak it myself to where I finally get the iRule to save without error, when I try to connect to the Sharepoint site I basically get "the website cannot be found" in Internet Explorer. Once I remove the iRule I can hit the site. So, I'm not sure what I need to adjust so that I can get the IP address of the member server to which the client connected without using the logfiles on the Big IP. I'd like to set up something that the Sharepoint admins can access to review without giving them Admin access to the BigIP. I know the sharepoint servers that are members of the pool have IIS logs that will show the IP address of the connecting client, but in this case the IIS logs just show the IP address of the load balancer, rather than the client workstation, so even if there is a way to pass the Client IP through without messing with connectivity?
when LB_SELECTED {
set whichserver [LB::server addr]
}
when HTTP_REQUEST {
if { string tolower [HTTP::uri] equals "/whichserver" } {
HTTP::respond 200 content "Real server IP is: $whichserver" noserver Content-Type
"text/html" Connection "Close"
Stop processing the iRule for this event here
return }
} - What_Lies_Bene1
Cirrostratus
It could be that you've used a line break that shouldn't be there on the line with HTTP::respond, it should all be one line. If it is still an issue, maybe it's the event order and we should skip one;when HTTP_REQUEST { if { string tolower [HTTP::uri] equals "/whichserver" } { HTTP::respond 200 content "Real server IP is: [LB::server addr]" noserver Content-Type "text/html" Connection "Close" Stop processing the iRule for this event here return } } - hoolio
Cirrostratus
Nice work yet again with these examples Steve!
There were outer square braces missing from the URI check:when HTTP_REQUEST { if { [string tolower [HTTP::uri]] equals "/whichserver" } { HTTP::respond 200 content "Real server IP is: [LB::server addr]" noserver Content-Type "text/html" Connection "Close" Stop processing the iRule for this event here return } }
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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