Forum Discussion
Anton_Koldaev_2
Feb 13, 2016Nimbostratus
How to read class value by key?
BigIP LTM 11.5.1
I have a data group type string. And I have key-value pairs inside.
Data group name:
test_dg
String Records:
key1 := value1
key2 := value2
How can I read "test[key1]" to get value1?
Will the following work?
set first_value [ class match --name -- "key1" equals test_dg ]
set second_value [ class match --name -- "key2" equals test_dg ]
set first_value [class lookup key1 test_dg] set second_value [class lookup key2 test_dg]
As the documentation states, this is equivalent to:
set first_value [class match -value key2 equals test_dg] set second_value [class match -value key2 equals test_dg]
- VernonWellsEmployee
set first_value [class lookup key1 test_dg] set second_value [class lookup key2 test_dg]
As the documentation states, this is equivalent to:
set first_value [class match -value key2 equals test_dg] set second_value [class match -value key2 equals test_dg]
- Anton_Koldaev_2NimbostratusThanks!
- Anton_Koldaev_2NimbostratusActually documentations as documenation states it'll return 0 or 1 but not the actual value: ``` The return value depends on the option specified. If no option was specified, the return value is 1 for a match and 0 for a no-match ```
- VernonWellsEmployeeThat's if "class match" is used without any options. As I say, "class lookup" is equivalent to "class match -value", so an option is supplied, namely '-value'.
- VernonWellsEmployee
To demonstrate, I did the following:
tmsh list ltm data-group internal test ltm data-group internal test records { abc { data 123 } def { data 456 } } type string tmsh list ltm rule test01 ltm rule test01 { when HTTP_REQUEST { set u [findstr [HTTP::path] / 1] set v [class lookup $u test] log local0. "With request-uri path = ([HTTP::path]), first element = ($u), value = ($v)" } }
A few log entries:
Rule /Common/test01 : With request-uri path = (/abc), first element = (abc), value = (123) Rule /Common/test01 : With request-uri path = (/def), first element = (def), value = (456) Rule /Common/test01 : With request-uri path = (/hij), first element = (hij), value = ()
- Anton_Koldaev_2NimbostratusThanks. That's very helpful.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects