<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating a custom where command in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Creating-a-custom-where-command/m-p/530869#M9535</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm new to creating custom search commands, and haven't been able to understand the examples in the SDK repo on GitHub, if someone can point me to or provide a step by step guide to achieve the below that'd be really appreciated.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; I need to filter my results to only include events where a field (cidr) is a subnet of a range entered on a dashboard ($search_cidr$).&lt;/P&gt;&lt;P&gt;As the builtin cidrmatch(CIDR, IP) only works with an IP and a CIDR range, I don't beleive I can do this natively, so I'm thinking a custom where command is the way to go, so I can do something like this in SPL:&lt;/P&gt;&lt;P&gt;| from datamodel:mymodel&lt;BR /&gt;| where SubnetOf(cidr, "$search_cidr$")&lt;/P&gt;&lt;P&gt;I've written a basic Python function in my apps bin directory to do the comparison, it takes either (IP, Subnet) or (Subnet. Subnet) and returns a boolean, however I don't know how to turn this into a filter for the where command to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python3
from ipaddress import ip_network


def SubnetOf(Needle, Haystack):
    try:
        Needle = ip_network(Needle)
        Haystack = ip_network(Haystack)
        return Needle.subnet_of(Haystack)
    except:
        return False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance to get me started would be great.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2020 18:42:01 GMT</pubDate>
    <dc:creator>joepjisc</dc:creator>
    <dc:date>2020-11-25T18:42:01Z</dc:date>
    <item>
      <title>Creating a custom where command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Creating-a-custom-where-command/m-p/530869#M9535</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm new to creating custom search commands, and haven't been able to understand the examples in the SDK repo on GitHub, if someone can point me to or provide a step by step guide to achieve the below that'd be really appreciated.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; I need to filter my results to only include events where a field (cidr) is a subnet of a range entered on a dashboard ($search_cidr$).&lt;/P&gt;&lt;P&gt;As the builtin cidrmatch(CIDR, IP) only works with an IP and a CIDR range, I don't beleive I can do this natively, so I'm thinking a custom where command is the way to go, so I can do something like this in SPL:&lt;/P&gt;&lt;P&gt;| from datamodel:mymodel&lt;BR /&gt;| where SubnetOf(cidr, "$search_cidr$")&lt;/P&gt;&lt;P&gt;I've written a basic Python function in my apps bin directory to do the comparison, it takes either (IP, Subnet) or (Subnet. Subnet) and returns a boolean, however I don't know how to turn this into a filter for the where command to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python3
from ipaddress import ip_network


def SubnetOf(Needle, Haystack):
    try:
        Needle = ip_network(Needle)
        Haystack = ip_network(Haystack)
        return Needle.subnet_of(Haystack)
    except:
        return False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance to get me started would be great.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 18:42:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Creating-a-custom-where-command/m-p/530869#M9535</guid>
      <dc:creator>joepjisc</dc:creator>
      <dc:date>2020-11-25T18:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a custom where command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Creating-a-custom-where-command/m-p/530897#M9536</link>
      <description>&lt;P&gt;AFAIK, the where command is not extensible.&amp;nbsp; You can do the equivalent with a custom command, though.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| from datamodel:mymodel
| SubnetOf needle=cidr haystack="$search_cidr$" result=foo
| where foo&lt;/LI-CODE&gt;&lt;P&gt;You'll need to convert your script into a Splunk streaming command, though.&amp;nbsp; See dev.splunk.com for more.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 21:02:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Creating-a-custom-where-command/m-p/530897#M9536</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-25T21:02:27Z</dc:date>
    </item>
  </channel>
</rss>

