# Logging if certain HTTP Query Strings are Null

**URL:** <https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [November 2, 2010, 2:07pm UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004 "2010-11-02T14:07:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [November 2, 2010, 2:07pm UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/1 "2010-11-02T14:07:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [November 2, 2010, 7:49pm UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/2 "2010-11-02T19:49:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [November 2, 2010, 7:58pm UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/3 "2010-11-02T19:58:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [November 3, 2010, 12:48am UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/4 "2010-11-03T00:48:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [November 3, 2010, 6:28am UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/5 "2010-11-03T06:28:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [November 3, 2010, 2:10pm UTC](https://community.f5.com/t/logging-if-certain-http-query-strings-are-null/58004/6 "2010-11-03T14:10:14Z")

</div>

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!
