Forum Discussion

smp_86112's avatar
smp_86112
Icon for Cirrostratus rankCirrostratus
May 13, 2010

Logging output of an expression

OK I feel really dumb having to post this question, so please hit me with kid gloves. I'm trying to do something that appeared to be very trivial at first glance...

All I want to do is log the output of a simple expression:


[HTTP::uri] equals "/myuri"

I believe this expression should evaluate to a 1 or a 0, and that's the value I want to log. This was my first attempt:


when HTTP_REQUEST {
  set val [[HTTP::uri] equals "/myuri"]
  log local0. "$val"
}

I've also tried this more simple approach:

when HTTP_REQUEST {
  log local0. "[[HTTP::uri] equals "/myuri"]"
}

By "try", I mean I've attempted all sorts of different placement of double-quotes, parenthesis, braces, and brackets. Either I get a syntax error updating the iRule, a TCL error "invalid command name "/myuri"", or the string [HTTP::uri] equals "/myuri". Is this a TCL thing, or am I just having trouble with the syntax?

3 Replies

  • Yes, fantastic...it's a TCL thing. It's never clear to me when I need to look at the iRules wiki versus TCL doc, and I have a tough time navigating the TCL doc...

     

     

    Regarding your response:

     

     

    you could use expr to do the same thing

     

     

     

    I'd like to make sure I understand. Is there another way to evaluate that expression without using the expr command?
  •  

    http://www.tcl.tk/man/tcl8.4/TclCmd/if.htm

     

     

    The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument).

     

     

     

    So if you're not using the expression in an if statement, you can use expr to do the evaluation. If it was a command you could execute it in square braces:

     

     

    log local0. "[string match "/myuri" [HTTP::uri]]"

     

     

    Aaron