Forum Discussion

Chris_Miller's avatar
Chris_Miller
Icon for Altostratus rankAltostratus
Nov 02, 2010

Logging if certain HTTP Query Strings are Null

I have a query string that looks like the following:

s_sample=test&t_sample=test&u_sample=test.

I'm trying to determine the most effective way to log when s_sample, t_sample, or u_sample don't have a value.

Thoughts?

5 Replies

  • Hi Chris,

     

     

    Are the parameter names always going to be set in the same order? Are you trying to log the query string only when all three are present and any of them don't have a value?

     

     

    I'm thinking you could use scan to do this.

     

     

    Aaron
  • Not pretty, but it seems to work assuming I have the scenario correct:

     

     

    scan [string range [HTTP::query] [string first "s_sample=" [HTTP::query]] end] {s_sample=%[^&]&t_sample=%[^&]&u_sample=%[^&]}

     

     

    Here is a description of the steps:

     

     

    Save a test query with some parameters and values including the three sample parameters in order

     

    set query {blah=val&s_sample=s_sample_value&t_sample=t_sample_value&u_sample=u_sample_value&blah=val2}

     

     

    Get the index of the first sample parameter

     

    string first "s_sample=" $query

     

     

    Trim off everything up to the first sample parameter name

     

    string range $query [string first "s_sample=" $query] end

     

     

    Scan the trimmed string to get the values for the three sample parameters. If it doesn't return 3, then one or more of the parameters wasn't matched and parsed

     

    scan [string range $query [string first "s_sample=" $query] end] {s_sample=%[^&]&t_sample=%[^&]&u_sample=%[^&]}

     

     

    I'm guessing there might be a cleaner solution if you can give more detail on the scenario.

     

     

    Aaron
  • Thanks for the quick reply Aaron!

     

     

    The query strings will always be in the same order. I'm being challenged to report on anytime when a query "string" exists but doesn't have a value after the "=" character. The 3 query types should always exist, but apparently might not always have a value.
  • If the query parameters are in the same order and consecutively listed, I think this will work:

     

     

    scan [string range [HTTP::query] [string first "s_sample=" [HTTP::query]] end] {s_sample=%[^&]&t_sample=%[^&]&u_sample=%[^&]}

     

     

    A more robust option would be to parse each parameter name and value using URI::query. But that seems like a lot of overhead if you're checking every request that has a query string. If you're only interested in requests to a specific URI, you could check for that first before using the scan command.

     

     

    Aaron
  • Posted By hoolio on 11/02/2010 11:28 PM

     

    If the query parameters are in the same order and consecutively listed, I think this will work:

     

     

    scan [string range [HTTP::query] [string first "s_sample=" [HTTP::query]] end] {s_sample=%[^&]&t_sample=%[^&]&u_sample=%[^&]}

     

     

    A more robust option would be to parse each parameter name and value using URI::query. But that seems like a lot of overhead if you're checking every request that has a query string. If you're only interested in requests to a specific URI, you could check for that first before using the scan command.

     

     

    Aaron

     

    Actually, I do only care about a specific URI. Thanks for that tip!