# Extensions 2.0 - How to use dimension filters

**URL:** <https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625>\
**Category:** Dynatrace Tips\
**Tags:** dynatrace-managed, extensions\
**Created:** [June 28, 2022, 9:39am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625 "2022-06-28T09:39:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [June 28, 2022, 9:39am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/1 "2022-06-28T09:39:10Z")

</div>

**Use case** : add [dimension filters](https://www.dynatrace.com/support/help/shortlink/extension-yaml#filters) to an [Extension 2.0 YAML](https://www.dynatrace.com/support/help/extend-dynatrace/extensions20/extension-yaml) so that unwanted data can be filtered out. This can be implemented in the “dimensions” section of each data source definition (under “group” or “subgroup”). This post will use “[snmp](https://www.dynatrace.com/support/help/extend-dynatrace/extensions20/data-sources/snmp-extensions/snmp-schema-reference)” as the data source, but the implementation is the same across all [other data sources](https://www.dynatrace.com/support/help/shortlink/extensions20#data-sources).

**Generic concept and syntax** :

You can add a filter to a dimension in one of two ways:

- **filter: const:\<filter-definition\>**
  - **const:** must be followed by a literal filter definition
  - **\<filter-definition\>** follows this syntax:
    - **$eq(\<str\>)**&nbsp;– check if&nbsp; **\<str\>** &nbsp;matches what you’re filtering
    - **$prefix(…)**&nbsp;– must begin with …
    - **$suffix(…)**&nbsp;- must end with …
    - **$contains(…)**&nbsp;– must contain …
    - **$and(\<expr1\>, \<expr2\>)**&nbsp;– can be used to chain two or more of the above expressions with AND operator
    - **$or(\<expr1\>, \<expr2\>)**&nbsp;– can be used to chain two or more of the above expressions with OR operator
    - **$not(\<expr\>)**&nbsp;– can be used to negate an expression

- **filter: var:\<var-id\>**
  - **var:** &nbsp;must be followed by the ID of a [defined variable](https://www.dynatrace.com/support/help/shortlink/extension-yaml#variables) (in the vars section)

**Example 1** - I’m collecting a **sensor.value** metric (oid 1.0.0.0.0.3) from a table of sensors of my snmp device. The table exposes a dimension called **sensor.type** (oid&nbsp;1.0.0.0.0.2) which is an integer value for the type of sensor. I know **sensor.type** 3 is a temperature sensor, so I only want to collect the value of this type of sensor. I will have to use filters to only select this dimension value.  
**YAML definition:**

```auto
snmp:<br> - group: metrics<br> interval:<br> minutes: 1<br> subgroups:<br> - subgroup: sensor-data<br> table: true<br> dimensions:<br> - key: sensor.type<br> value: oid:1.0.0.0.0.2<br> filter: const:$eq(3)<br> metrics:<br> - key: sensor.value<br> value: oid:1.0.0.0.0.3

```

**Example 2** - The F5 device has a lot of Traffic Profiles that may not be needed for monitoring. I want users to be able to filter out Traffic Profiles that they don’t want monitored. I must create a variable where users can enter syntax to filter out this data.

**YAML definition:**

```auto
vars:<br> id: profile-name-filter<br> type: pattern<br> displayName: Pattern to filter which Profies are monitored<br><br>snmp:<br> - group: traffic-profiles<br> interval:<br> minutes: 1<br> subgroups:<br> - subgroup: profile-metrics<br> table: true<br> dimensions:<br> - key: profile.name<br> value: oid:2.0.0.0.0.1<br> filter: var:profile-name-filter<br> metrics:<br> - key: some.profile.metric<br> value: oid:2.0.0.0.0.8

```

Note: the variable field in the Monitoring configuration will take the same syntax as the literal filter definition explained earlier. The users see this:

![Radu_0-1656408990298.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/230b9ba1158d1591e5b526549d5681709fa67487.png)

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [June 28, 2022, 11:24am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/2 "2022-06-28T11:24:43Z")

</div>

So this filtering should work?

(It doesnt)

```auto
- <span>subgroup</span>: ResourceGroup<br> <span>wmiNamespace</span>: <span>"root\\mscluster"<br></span> <span>query</span>: SELECT State,Name FROM MSCluster_ResourceGroup WHERE Name!='Available Storage'<br> <span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresourcegroup.state<br> <span>value</span>: column:State<br> <span>dimensions</span>:<br> - <span>key</span>: resourcegroup.name<br> <span>value</span>: Name<br> <span>filter</span>: const:$contains("Clu")

```

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [June 28, 2022, 11:27am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/3 "2022-06-28T11:27:36Z")

</div>

Please remove the quotes around Clu.

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [June 28, 2022, 11:31am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/4 "2022-06-28T11:31:28Z")

</div>

And also remember that value extraction in WMI always happens from Columns.

You correct dimension definition is:

```auto
- key: resourcegroup.name<br> value: column:Name<br> filter: const:$contains(Clu)

```

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [June 28, 2022, 11:50am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/5 "2022-06-28T11:50:30Z")

</div>

It doesn’t work.

Should I open a support case then?

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [June 28, 2022, 11:51am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/6 "2022-06-28T11:51:15Z")

</div>

This is the entire yaml:

```auto
<span>name</span>: <span>"custom:com.kanari.extension.wmi-cl"<br></span><span>version</span>: <span>"1.0.48"<br></span><span>minDynatraceVersion</span>: <span>"1.225"<br></span><span>author</span>:<br> <span>name</span>: <span>"Kanari AS"<br></span><span><br></span><span>vars</span>:<br> - <span>id</span>: resourceGroupFilter<br> <span>displayName</span>: Resource Group Filter<br> <span>type</span>: pattern<br> - <span>id</span>: resourceFilter<br> <span>displayName</span>: Resource Filter<br> <span>type</span>: pattern<br> - <span>id</span>: nodeFilter<br> <span>displayName</span>: Node Filter<br> <span>type</span>: pattern<br> - <span>id</span>: networkinterfaceFilter<br> <span>displayName</span>: Network Interface Filter<br> <span>type</span>: pattern<br><br><span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresourcegroup.state<br> <span>metadata</span>:<br> <span>displayName</span>: Cluster ResourceGroup State<br> <span>description</span>: State of the cluster resource group<br> <span>unit</span>: Count<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresource.state<br> <span>metadata</span>:<br> <span>displayName</span>: Cluster Resource State<br> <span>description</span>: State of the cluster resource<br> <span>unit</span>: Count<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusternode.state<br> <span>metadata</span>:<br> <span>displayName</span>: Cluster Node State<br> <span>description</span>: State of the cluster node<br> <span>unit</span>: Count<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusternetworkinterface.state<br> <span>metadata</span>:<br> <span>displayName</span>: Cluster Network Interface State<br> <span>description</span>: State of the cluster network interface<br> <span>unit</span>: Count<br><br><br><br><span>wmi</span>:<br> - <span>group</span>: Host<br> <span>interval</span>: 1m<br> <span>subgroups</span>:<br> - <span>subgroup</span>: Resource<br> <span>wmiNamespace</span>: <span>"root\\mscluster"<br></span> <span>query</span>: SELECT State,Name FROM MSCluster_Resource<br> <span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresource.state<br> <span>value</span>: column:State<br> <span>dimensions</span>:<br> - <span>key</span>: resource.name<br> <span>value</span>: column:Name<br><br> - <span>subgroup</span>: Node<br> <span>wmiNamespace</span>: <span>"root\\mscluster"<br></span> <span>query</span>: SELECT State,Name FROM MSCluster_Node<br> <span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusternode.state<br> <span>value</span>: column:State<br> <span>dimensions</span>:<br> - <span>key</span>: node.name<br> <span>value</span>: column:Name<br><br> - <span>subgroup</span>: ResourceGroup<br> <span>wmiNamespace</span>: <span>"root\\mscluster"<br></span> <span>query</span>: SELECT State,Name FROM MSCluster_ResourceGroup WHERE Name!='Available Storage'<br> <span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresourcegroup.state<br> <span>value</span>: column:State<br> <span>dimensions</span>:<br> - <span>key</span>: resourcegroup.name<br> <span>value</span>: column:Name<br> <span>filter</span>: var:resourceGroupFilter<br> - <span>subgroup</span>: Node<br> <span>wmiNamespace</span>: <span>"root\\mscluster"<br></span> <span>query</span>: SELECT State,Name FROM MSCluster_NetworkInterface<br> <span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusternetworkinterface.state<br> <span>value</span>: column:State<br> <span>dimensions</span>:<br> - <span>key</span>: networkinterface.name<br> <span>value</span>: column:Name<br><br><span>#vars:<br></span><span># - id: resourceGroupFilter<br></span><span># displayName: Pattern matching Resource Groups which should be ignored<br></span><span># type: pattern<br></span><span><br></span><span>dashboards</span>:<br> - <span>path</span>: <span>"dashboards/windows_failover_clustering.json"<br></span><span><br></span><span>alerts</span>:<br> - <span>path</span>: <span>"alerts/node_high.json"<br></span> - <span>path</span>: <span>"alerts/node_low.json"<br></span> - <span>path</span>: <span>"alerts/cluster_resource_high.json"<br></span> - <span>path</span>: <span>"alerts/cluster_resource_low.json"<br></span> - <span>path</span>: <span>"alerts/cluster_resourcegroup_high.json"<br></span> - <span>path</span>: <span>"alerts/cluster_resourcegroup_low.json"<br></span> - <span>path</span>: <span>"alerts/nic_low.json"<br></span><span><br></span><span>screens</span>:<br> - <span>entityType</span>: wmi:com_kanari_extension_wmi_cluster_instance<br> <span>detailsSettings</span>:<br> <span>staticContent</span>:<br> <span>showProblems</span>: true<br> <span>showProperties</span>: true<br> <span>showTags</span>: true<br> <span>showGlobalFilter</span>: true<br> <span>showAddTag</span>: true<br> <span>layout</span>:<br> <span>autoGenerate</span>: false<br> <span>cards</span>:<br> - <span>type</span>: <span>"CHART_GROUP"<br></span> <span>key</span>: <span>"host-clusterresources"<br></span> <span>propertiesCard</span>:<br> <span>properties</span>:<br> - <span>type</span>: RELATION<br> <span>relation</span>:<br> <span>entitySelectorTemplate</span>: type(host), toRelationships.runsOn($(entityConditions))<br> <span>displayName</span>: Host<br> <span>chartsCards</span>:<br> - <span>key</span>: <span>"host-clusterresources"<br></span> <span>displayName</span>: <span>"Cluster Resources"<br></span> <span>numberOfVisibleCharts</span>: 3<br> <span>charts</span>:<br> - <span>displayName</span>: <span>"Cluster ResourceGroup State"<br></span> <span>metrics</span>:<br> - <span>metricSelector</span>: <span>"com.kanari.extension.wmi-cl.host.clusterresourcegroup.state:SplitBy(\"resourcegroup.name\")"<br></span> - <span>displayName</span>: <span>"Cluster Resource State"<br></span> <span>metrics</span>:<br> - <span>metricSelector</span>: <span>"com.kanari.extension.wmi-cl.host.clusterresource.state:SplitBy(\"resource.name\")"<br></span> - <span>displayName</span>: <span>"Cluster Network Interface State"<br></span> <span>metrics</span>:<br> - <span>metricSelector</span>: <span>"com.kanari.extension.wmi-cl.host.clusternetworkinterface.state:SplitBy(\"networkinterface.name\")"<br></span><span># entitiesListCards:<br></span><span># - key: "cluster-nic-list"<br></span><span># displayName: "Network Interfaces List"<br></span><span># entitySelectorTemplate: "type(wmi:com_kanari_extension_wmi_cluster_network_interface),fromRelationships.runsOn($(entityConditions))"<br></span><span># displayCharts: false<br></span><span># displayIcons: true<br></span><span># enableDetailsExpandability: tru<br></span><span>topology</span>:<br> <span>types</span>:<br> - <span>name</span>: wmi:com_kanari_extension_wmi_cluster_instance<br> <span>displayName</span>: Cluster Instance<br> <span>enabled</span>: true<br> <span>rules</span>:<br> - <span>idPattern</span>: wmi_cluster_instance_{dt.entity.host}<br> <span>sources</span>:<br> - <span>sourceType</span>: Metrics<br> <span>condition</span>: $prefix(com.kanari.extension.wmi-cl.host)<br> <span>attributes</span>: []<br> <span>requiredDimensions</span>: []<br> <span>instanceNamePattern</span>: Cluster Instance on {dt.entity.host}<br> - <span>idPattern</span>: wmi_cluster_instance_{host}<br> <span>sources</span>:<br> - <span>sourceType</span>: Metrics<br> <span>condition</span>: $prefix(com.kanari.extension.wmi-cl.host)<br> <span>attributes</span>: []<br> <span>requiredDimensions</span>: []<br> <span>instanceNamePattern</span>: Cluster Instance on {host}<br> - <span>name</span>: wmi:com_kanari_extension_wmi_cluster_network_interface<br> <span>displayName</span>: Cluster Network Interface<br> <span>enabled</span>: true<br> <span>rules</span>:<br> - <span>idPattern</span>: wmi_cluster_network_interface_{dt.entity.host}<br> <span>sources</span>:<br> - <span>sourceType</span>: Metrics<br> <span>condition</span>: $prefix(com.kanari.extension.wmi-cl.host.clusternetworkinterface)<br> <span>attributes</span>: []<br> <span>requiredDimensions</span>: []<br> <span>instanceNamePattern</span>: Cluster Network Interface on {dt.entity.host}

```

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [July 1, 2022, 8:16am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/7 "2022-07-01T08:16:13Z")

</div>

Hi&nbsp;[@tarjei](https://community.dynatrace.com/user/12960)

After some discussions I found out that for WMI, due to performance reasons, the filtering within the dimensions definition is disabled. Instead, filtering should be applied directly within the query. You can still use variables to expose the filter as a configuration parameter.

This means that for WMI, the filtering takes [WQL syntax](https://docs.microsoft.com/en-us/windows/win32/wmisdk/where-clause) and not the syntax I documented eariler.

The example from your extension would be:

```auto
<span>query</span>: SELECT State,Name FROM MSCluster_ResourceGroup WHERE Name!='Available Storage' var:resourceGroupFilter<br><span>metrics</span>:<br> - <span>key</span>: com.kanari.extension.wmi-cl.host.clusterresourcegroup.state<br> <span>value</span>: column:State<br><span>dimensions</span>:<br> - <span>key</span>: resourcegroup.name<br> <span>value</span>: column:Name

```

Where resourceGroupFilter is a variable defined as before. Within the monitoring configuration you will have to add the additional syntax. For example, “Name starts with Clu” would be “AND Name LIKE ‘Clu%’”

Could you try this approach and let me know if it fixes your issue?

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [July 1, 2022, 9:41am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/8 "2022-07-01T09:41:20Z")

</div>

Ok,

Thank you! 🙂 I will try this. But you do understand my frustration with this?

Would you happen to know when the documentation for ext 2.0 will get the desired TLC?

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [July 1, 2022, 11:20am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/9 "2022-07-01T11:20:44Z")

</div>

I tried it, but it did not work.

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [July 1, 2022, 11:34am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/10 "2022-07-01T11:34:51Z")

</div>

Could you try one final variation please. Change the query to

```auto
<span>query</span>: SELECT State,Name FROM MSCluster_ResourceGroup WHERE var:resourceGroupFilter

```

And add the whole Name filter in the var field of the UI.

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [July 1, 2022, 12:12pm UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/11 "2022-07-01T12:12:10Z")

</div>

Hi!

I have now tried multiple variants of this, but it doesnt work.

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [February 7, 2023, 2:11pm UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/12 "2023-02-07T14:11:18Z")

</div>

Hi&nbsp;[@Radu](https://community.dynatrace.com/user/22272)&nbsp;this does not work. Is this because I have to use a specific schema version?

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [February 7, 2023, 2:19pm UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/13 "2023-02-07T14:19:07Z")

</div>

Hi!

I see that in Dynatrace IIS Extension, there is dimension filtering. That plugin is using 1.245 schema.

[Microsoft IIS | Dynatrace Hub](https://www.dynatrace.com/hub/detail/microsoft-iis/?query=remote+w&offered=dynatrace#screenshots)

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [February 7, 2023, 2:38pm UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/14 "2023-02-07T14:38:18Z")

</div>

Please open a support ticket so we can troubleshoot this. The query looks correct but there may be other things happening that we cannot tell from the YAML alone.

---

<div class="post-metadata">

**Author:** ![tarjei](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tarjei/32/39196_2.png) [@tarjei](https://community.dynatrace.com/u/tarjei)\
**Post date:** [February 7, 2023, 4:10pm UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/15 "2023-02-07T16:10:07Z")

</div>

Hi!

I have an ongoing discussion for this, will make them open a support case for it. Thank you!

---

<div class="post-metadata">

**Author:** ![jegron](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jegron/32/12797_2.png) [@jegron](https://community.dynatrace.com/u/jegron)\
**Post date:** [December 5, 2023, 10:45am UTC](https://community.dynatrace.com/t/extensions-2-0-how-to-use-dimension-filters/35625/16 "2023-12-05T10:45:12Z")

</div>

Hi&nbsp;[@Radu](https://community.dynatrace.com/user/22272)&nbsp;!

I believe there might not be any documentation available on this subject currently. Would it be possible to reach out to the documentation team for further information on this?

Additionally, I’m looking to filter only interfaces specifically with the prefix ‘#’ :

_vars:_  
_- id: if\_alias_  
_type: text_  
_displayName: Pattern to filter capturing of Interfaces by Interface Alias_

_dimensions:_  
_- key: if.alias_  
_value: oid:1.3.6.1.2.1.31.1.1.1.18_  
_filter: var:if\_alias_

I tried this syntax :

![jegron_0-1701772690529.png](https://global.discourse-cdn.com/dynatrace/original/3X/a/f/af144f7b744a0323fd770419d007d87ed5f05f63.png)

It works but I also obtain all the interfaces which do not have the if alias filled in. How can I exclude them?
