# Retrieve Value from Data Group record

**URL:** <https://community.f5.com/t/retrieve-value-from-data-group-record/58463>\
**Category:** Technical Forums\
**Tags:** ltm, application-delivery\
**Created:** [March 24, 2017, 9:26pm UTC](https://community.f5.com/t/retrieve-value-from-data-group-record/58463 "2017-03-24T21:26:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azzeddine\_S](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/azzeddine_s/32/15782_2.png) [@Azzeddine\_S](https://community.f5.com/u/Azzeddine_S)\
**Post date:** [March 24, 2017, 9:26pm UTC](https://community.f5.com/t/retrieve-value-from-data-group-record/58463/1 "2017-03-24T21:26:35Z")

</div>

Hi all

i am trying to write an irule to drop client paket by source IP, but instead of calling the IP in the rule as a condition , i want to add a location as a data value in the data group and apply the conditin on it my data group looks like :

ltm data-group internal Locations {

```tcl
records {
    10.1.1.0/24 {
        data paris/allow
    }
    10.1.2.0/24 {
        data ny/allow
    }
    10.10.1.100/32 {
        data my_self/drop
    }
    172.16.1.0/24 {
        data tokyo/allow
    }
    192.168.1.0/24 {
        data London/drop
    }
    192.168.100.0/24 {
        data moon/allow
    }
}
type ip

```

}

the condition is stored in the data group

wy question is how to get data from the records and since we can have multiple match how can we get data.

hope my question is enough clear …

---

<div class="post-metadata">

**Author:** ![Vijay\_E](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay\_E](https://community.f5.com/u/Vijay_E)\
**Post date:** [March 24, 2017, 11:57pm UTC](https://community.f5.com/t/retrieve-value-from-data-group-record/58463/2 "2017-03-24T23:57:12Z")

</div>

Look [here](https://devcentral.f5.com/wiki/iRules.class.ashx).

You need something like:

```tcl
class match -value equals

```

An example iRule can be found in this [thread](https://devcentral.f5.com/questions/irule-to-read-key-value-pair-from-data-group-lists).

---

<div class="post-metadata">

**Author:** ![Jeremy\_Church\_3](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Jeremy\_Church\_3](https://community.f5.com/u/Jeremy_Church_3)\
**Post date:** [March 25, 2017, 4:29am UTC](https://community.f5.com/t/retrieve-value-from-data-group-record/58463/3 "2017-03-25T04:29:41Z")

</div>

Hello,

When using a data-group of

```tcl
type ip

```

, the longest match wins.

In the example data-group you provide, I don’t see overlapping entries so I’ll provide an example that does have entries that overlap.

```tcl
ltm data-group internal Locations {
    records {
        10.1.1.0/24 {
            data "paris allow"
        }
        10.1.2.0/24 {
            data "ny allow"
        }
        10.1.2.96/29 {
            data "lab drop"
        }
        10.10.1.100/32 {
            data "my_self drop"
        }
        172.16.1.0/24 {
            data "tokyo allow"
        }
        192.168.1.0/24 {
            data "London drop"
        }
        192.168.100.0/24 {
            data "moon allow"
        }
    }
    type ip
}
ltm rule ALLOW_BY_IP {
    when RULE_INIT {
     test Locations data-group
    if {[TMM::cmp_unit] == 0} {
        foreach IP {10.1.1.1 10.1.2.10 10.1.2.99 10.10.1.100 192.168.100.230 172.30.1.1} {
            log local0. "address ${IP}: matches entry \
            \x22[class match -name $IP equals Locations]\x22 \
            and has value of \x22[class lookup $IP Locations]\x22"
        } else {
            log local0. "no match found for address $IP"
        }
    }
}
when CLIENT_ACCEPTED {
    set VAL [class lookup [IP::client_addr] Locations]
    switch -- [lindex $VAL 1] {
        allow {
            log local0. "allow connection from [lindex $VAL 0] \
            w/IP [IP::client_addr]: entry [class match -name [IP::client_addr] equals Locations]"
        }
        drop {
            log local0. "reject connection from [lindex $VAL 0] \
            w/IP [IP::client_addr]: entry [class match -name [IP::client_addr] equals Locations]"
            reject
        }
        default { log locla0. "no match found or the match did not have allow/drop" }
    }
}
}

```

Notes

1. Instead of the syntax **name/action** , I chose **“name action”**. This skips the step of having to split them manually in the iRule.

2. Added a

3. In the

Is this what you were looking for?

---

<div class="post-metadata">

**Author:** ![Azzeddine\_S](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/azzeddine_s/32/15782_2.png) [@Azzeddine\_S](https://community.f5.com/u/Azzeddine_S)\
**Post date:** [March 26, 2017, 8:44am UTC](https://community.f5.com/t/retrieve-value-from-data-group-record/58463/4 "2017-03-26T08:44:42Z")

</div>

thanks a lot

the answer is more than what i expected

i really apriciate the effort and i will give you a feed back about the result as soon i deploy it

once again thanks a lot
