<?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 Re: Multiple Values for open ports, trying to table only the open ones in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666152#M228529</link>
    <description>&lt;P&gt;Thank you. I knew there was probably some way to iterate, but couldnt figure it out. Thank you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 13:43:00 GMT</pubDate>
    <dc:creator>Abass42</dc:creator>
    <dc:date>2023-10-25T13:43:00Z</dc:date>
    <item>
      <title>Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666066#M228501</link>
      <description>&lt;P&gt;I was asked to create a query that will allow the user to see only the open ports. An example log looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;10/24/2023 06:00:04,source=SXXXX-88880000,destination=10.10.100.130,DuBlIn_,11.11.119.111,port_80=True,port_443=True,port_21=False,port_22=True,port_25=False,port_53=False,port_554=False,port_139=False,port_445=False,port_123=False,port_3389=False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it looks easy enough, I want to table port_*=True.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want destination, src_ip, and the open ports.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I asked our equivalent of Chat GPT about it, and I got this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=gpss sourcetype=acl "SXXXXXXX" destination="11.11.111.11"
| eval open_ports = case(
    port_123=="True", "123",
    port_139=="True", "139",
    port_21=="True", "21",
    port_22=="True", "22",
    port_25=="True", "25",
    port_3389=="True", "3389",
    port_443=="True", "443",
    port_445=="True", "445",
    port_53=="True", "53",
    port_554=="True", "554",
    port_80=="True", "80",
    true(), null()
)
| where open_ports!=null()
| mvexpand open_ports
| table _time, destination, gpss_src_ip, open_ports&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the &lt;EM&gt;open_ports!=null()&lt;/EM&gt; wasnt allowed.&amp;nbsp; I get a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Error in 'where' command: Type checking failed. The '!=' operator received different types.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;During testing, I have a baseline event, an event with three open Ports, but that search I ran only outputs the first one in the list. It hits port 22 first, since thats the first on in the case statement that is true.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Abass42_1-1698176311835.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27765i27042DEDBA99C56D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Abass42_1-1698176311835.png" alt="Abass42_1-1698176311835.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Abass42_2-1698176540749.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27766i939AA4A04A5751C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Abass42_2-1698176540749.png" alt="Abass42_2-1698176540749.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My main question is, How do I successfully tell splunk to only grab the open ports that are True? Can i even do a wildcard somewhere, and request to pull &lt;EM&gt;port_* WHERE True&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Thank you for any help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 19:45:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666066#M228501</guid>
      <dc:creator>Abass42</dc:creator>
      <dc:date>2023-10-24T19:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666077#M228505</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254220"&gt;@Abass42&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can achieve this using the&amp;nbsp;&lt;A title="See splunk docs for ForEach" href="https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Foreach" target="_blank" rel="noopener"&gt;foreach&lt;/A&gt;&amp;nbsp;command.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="10/24/2023 06:00:04,source=SXXXX-88880000,destination=10.10.100.130,DuBlIn_,11.11.119.111,port_80=True,port_443=True,port_21=False,port_22=True,port_25=False,port_53=False,port_554=False,port_139=False,port_445=False,port_123=False,port_3389=False"
| extract
``` Above is to generate the test data ```

``` Iterate through each port_xxx field to pick out the open ones ```
| foreach port_* [| eval open_ports=if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=="True", mvappend(open_ports, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"), open_ports)]

| mvexpand open_ports
| table _time, destination, gpss_src_ip, open_ports&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We use foreach to pick out all the fields that start with &lt;EM&gt;port_&lt;/EM&gt; and test to see if they are true. If they are, we add the number part of the field name (&lt;EM&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/EM&gt;) to a new multivalue field.&lt;/P&gt;&lt;P&gt;Then we continue with your mvexpand and table to show the results.&lt;/P&gt;&lt;P&gt;The results look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danspav_0-1698183837992.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27771i163BBE07A4095343/image-size/large?v=v2&amp;amp;px=999" role="button" title="danspav_0-1698183837992.png" alt="danspav_0-1698183837992.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;A title="See foreach in splunk docs" href="https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Foreach" target="_blank" rel="noopener"&gt;Splunk Docs page for ForEach&lt;/A&gt; explains the use of &lt;EM&gt;&amp;lt;&amp;lt;FIELD&amp;gt;&lt;/EM&gt; and &lt;EM&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;BR /&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 21:47:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666077#M228505</guid>
      <dc:creator>danspav</dc:creator>
      <dc:date>2023-10-24T21:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666089#M228510</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254220"&gt;@Abass42&lt;/a&gt;&amp;nbsp;,..&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;tried with rex and its working good.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="10/24/2023 06:00:04,source=SXXXX-88880000,destination=10.10.100.130,DuBlIn_,11.11.119.111,port_80=True,port_443=True,port_21=False,port_22=True,port_25=False,port_53=False,port_554=False,port_139=False,port_445=False,port_123=False,port_3389=False"
| extract
| rex max_match=5 field=_raw "port\_(?P&amp;lt;open_ports&amp;gt;\d+)\=True"
| mvexpand open_ports
| table _time, destination, gpss_src_ip, open_ports&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 25 Oct 2023 03:27:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666089#M228510</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2023-10-25T03:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666151#M228528</link>
      <description>&lt;P&gt;Thank you. That did the trick. Adding a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;| stats values(open_ports) by destination&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;allows me to group and add them all in one row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Abass42_0-1698241326015.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27783iBDD6606DA3988572/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Abass42_0-1698241326015.png" alt="Abass42_0-1698241326015.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you again for the prompt help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 13:42:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666151#M228528</guid>
      <dc:creator>Abass42</dc:creator>
      <dc:date>2023-10-25T13:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666152#M228529</link>
      <description>&lt;P&gt;Thank you. I knew there was probably some way to iterate, but couldnt figure it out. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 13:43:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666152#M228529</guid>
      <dc:creator>Abass42</dc:creator>
      <dc:date>2023-10-25T13:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Values for open ports, trying to table only the open ones</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666203#M228544</link>
      <description>&lt;P&gt;ne in the future, this is the final query I went with. I was trying to group any event in a certain index and sourcetype.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;index=test sourcetype=test2 source=*
| rex field=test_city "(?&amp;lt;city&amp;gt;[A-Za-z]+)_$"
| eval has_true_port = case(
    port_123="True" OR port_139="True" OR port_21="True" OR port_22="True" OR port_25="True" OR port_3389="True" OR port_443="True" OR port_445="True" OR port_53="True" OR port_554="True" OR port_80="True", 
    "Yes",
    true(),
    "No"
) 
| where has_true_port = "Yes" 
| stats values(port_123) as port_123, values(port_139) as port_139, values(port_21) as port_21, values(port_22) as port_22, values(port_25) as port_25, values(port_3389) as port_3389, values(port_443) as port_443, values(port_445) as port_445, values(port_53) as port_53, values(port_554) as port_554, values(port_80) as port_80 values(city) as City by destination, test_src_ip
| eval open_ports = if(port_123="True", "123,", "") . if(port_139="True", "139,", "") . if(port_21="True", "21,", "") . if(port_22="True", "22,", "") . if(port_25="True", "25,", "") . if(port_3389="True", "3389,", "") . if(port_443="True", "443,", "") . if(port_445="True", "445,", "") . if(port_53="True", "53,", "") . if(port_554="True", "554,", "") . if(port_80="True", "80,", "")
| eval open_ports = rtrim(open_ports, ",")
| table destination, test_src_ip City open_ports&lt;/PRE&gt;&lt;P&gt;The result looks a bit like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Abass42_1-1698253175112.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27800i399AC44B23BD3CCF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Abass42_1-1698253175112.png" alt="Abass42_1-1698253175112.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, this combines each open port into one row while also sorting by destination ip and source IP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 16:59:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-Values-for-open-ports-trying-to-table-only-the-open/m-p/666203#M228544</guid>
      <dc:creator>Abass42</dc:creator>
      <dc:date>2023-10-25T16:59:43Z</dc:date>
    </item>
  </channel>
</rss>

