Forum Discussion

Mike_Dayton_108's avatar
Mike_Dayton_108
Icon for Nimbostratus rankNimbostratus
Jul 26, 2016
Solved

Using a Data-Group string values in 11 code, can you match in both directions?

In the DG where string x=y, I know I can match x and translate to y. Can I also match y and get x?  
  • Vernon_97235's avatar
    Jul 26, 2016

    Not without iterating through each element. A data-group is like an associative array (aka map, aka dictionary). In other words, it's a set of key/value pairs, where lookups are by key, not value. If you want to perform such a lookup, you should duplicate in your data-group each entry with the key and value reversed. Naturally, the keys must be unique, so if the same value exists for more than one key, then it won't work.

    In case you care, the iteration would be like this:

    when HTTP_REQUEST {
        foreach kv [class get dg-your-data-group] {
            log local0. "key = [lindex $kv 0], value = [lindex $kv 1]" 
        }
    }