I would like to remove the routing domain suffix “%1” in the log file i’m creating.
Here’s a sample of my Irule.
when HTTP_REQUEST { set client_ip [IP::remote_addr] set log_msg “” append log_msg “$client_ip”
The result in the log file is “192.168.1.5%1” but i need to have it without the “%1”. I’m wondering if a regex could do the job inside my Irule but i’m stucked in finding a way. Any help would be appreciated Aurel
Hello guys, Thanks for your reply. Kevin, i actually don’t understand the how to use it from your examples.(sorry about it) I did understand yours nitass, and i forgot to mention something else. I actually need to match string that could be “%[1-9][1-9][1-9]” (in a regex syntax). But this is not working with tcl, the way i tried anyway.
I was showing you performance output using TCLSH from the command line and the time command. It’s probably not likely that you have more than a few defined route domains, all of which you know about in advance, so a literal string map is probably most efficient:
If, however, you truly need something more dynamic, then a regular expression will work. Keep in mind of course that a regular expression is, in general, going to be more CPU-intensive.
% set test1 "10.10.10.10%1"
10.10.10.10%1
% set test123 "10.10.10.10%123"
10.10.10.10%123
% scan $test1 {%[^%%]%%%d} a b
2
% put $a
10.10.10.10
% put $b
1
% scan $test123 {%[^%%]%%%d} a b
2
% put $a
10.10.10.10
% put $b
123
%
% set test1 "10.10.10.10%1"
10.10.10.10%1
% set test123 "10.10.10.10%123"
10.10.10.10%123
% scan $test1 {%[^%%]%%%d} a b
2
% put $a
10.10.10.10
% put $b
1
% scan $test123 {%[^%%]%%%d} a b
2
% put $a
10.10.10.10
% put $b
123
%
The scan and regsub commands both work on regular expressions, so both will do a better job of matching a dynamic set of numbers - at the expense of performance. I’m doubtful that you have a large set of dynamic route domain assignments, so given the assumption that 1) it’s a small set, and 2) you already know what those RD values are, an explicit [string map] is probably more efficient. But I want to express that [string map] is an explicit search - you have to know what you’re looking for. In your case, since “223” is the RD number, your syntax would look something like this:
Yes Nitass, this is doing the job fine. That’s seems fine. As Kevin said, it looks that is using regex and then will consume CPU a little more than “tcl native” commands. Am i right ? I’d like (as far as possible) to do this with the fewest impact on performance.
Yes Nitass, this is doing the job fine. That’s seems fine. As Kevin said, it looks that is using regex and then will consume CPU a little more than “tcl native” commands. Am i right ? I’d like (as far as possible) to do this with the fewest impact on performance.