<?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 how to find in which groups a network object exists in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/147524#M6793</link>
    <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to find a Linux command with which I can see in which groups there is an object that I give like the existing function in the Smart-Console "where-used"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have this script and I want to get for each object in which groups he exists. like as I get the name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;mgmt_cli -r true show-group name "group" --format json | jq -r '.members[] | [.name, ."ipv4-address", .subnet4, .type ] | @csv' -r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 01 May 2022 13:19:00 GMT</pubDate>
    <dc:creator>MichaelGur</dc:creator>
    <dc:date>2022-05-01T13:19:00Z</dc:date>
    <item>
      <title>how to find in which groups a network object exists</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/147524#M6793</link>
      <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to find a Linux command with which I can see in which groups there is an object that I give like the existing function in the Smart-Console "where-used"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have this script and I want to get for each object in which groups he exists. like as I get the name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;mgmt_cli -r true show-group name "group" --format json | jq -r '.members[] | [.name, ."ipv4-address", .subnet4, .type ] | @csv' -r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2022 13:19:00 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/147524#M6793</guid>
      <dc:creator>MichaelGur</dc:creator>
      <dc:date>2022-05-01T13:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to find in which groups a network object exists</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148058#M6805</link>
      <description>&lt;P&gt;Maybe these community solutions are of help?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/What-s-an-example-of-where-used-indirectly/m-p/5245/highlight/true#M443" target="_self"&gt;where-used indirectly&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.checkpoint.com/t5/Management/R80-10-Where-Used-object/m-p/34559" target="_self"&gt;where-used object&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/quot-where-used-quot-does-quot-publish-quot/td-p/136337" target="_self"&gt;where used does publish?&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/Where-Used-Indirect-Limited-Results/td-p/89091" target="_self"&gt;where-used limited results&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/FW-object-rule-report/td-p/25994" target="_self"&gt;where-used rule report&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;and many others&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 06 May 2022 16:02:19 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148058#M6805</guid>
      <dc:creator>Danny</dc:creator>
      <dc:date>2022-05-06T16:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to find in which groups a network object exists</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148060#M6806</link>
      <description>&lt;P&gt;Danny pointed you to very good resources but I'm jumping in the ring&amp;nbsp; for the challenge.&lt;/P&gt;&lt;P&gt;I'm not much of a bash coding pro and much less with jq so here's a simple bash script that will collect your hosts and networks, log them in a CSV, display in which group(s) they can be found if any then deletes the CSV. I use grep with jq as playing with the latter's syntax was breaking the mood of my Friday evening.&lt;/P&gt;&lt;P&gt;don't forget to chmod +x the file before running it.&lt;/P&gt;&lt;P&gt;I named it obj2grp but make your pick.&lt;/P&gt;&lt;P&gt;&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;#!/bin/bash
mgmt_cli -r true show hosts --format json |jq -r '.objects[] | [.name] | @csv' -r &amp;gt; obj.csv
mgmt_cli -r true show networks --format json | jq -r '.objects[] | [.name] | @csv' -r &amp;gt;&amp;gt; obj.csv

while read line
do
        a=`mgmt_cli -r true where-used name $line --format json | jq -r '."used-directly"[]' | grep name | grep -v SMC`
        echo "Object $line is found in $a"
done &amp;lt; obj.csv
rm obj.csv&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a sample output.&lt;/P&gt;&lt;P&gt;&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;Object "cphost-1" is found in     "name": "cpgroup-1",
Object "cphost-100" is found in     "name": "cpgroup-5",
Object "cphost-2" is found in     "name": "cpgroup-2",
    "name": "cpgroup-1",
Object "cphost-200" is found in     "name": "cpgroup-5",
Object "CP_default_Office_Mode_addresses_pool" is found in
Object "cpnet_172.16.15.0-25" is found in     "name": "cpgroup-4",
Object "IPv6_Link_Local_Hosts" is found in
Object "net_10.20.10.0-24" is found in     "name": "cpgroup-1",&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can certainly improve it from there.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 18:34:29 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148060#M6806</guid>
      <dc:creator>Alex-</dc:creator>
      <dc:date>2022-05-06T18:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to find in which groups a network object exists</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148103#M6807</link>
      <description>&lt;P&gt;Here's an improved version of code which should increase readability. It uses the maximum limit of 500 objects processed at once, if you have more, use offset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#!/bin/bash
mgmt_cli -r true show hosts limit 500 --format json |jq -r '.objects[] | [.name] | @csv' -r &amp;gt; obj.csv
mgmt_cli -r true show networks limit 500 --format json | jq -r '.objects[] | [.name] | @csv' -r &amp;gt;&amp;gt; obj.csv

while read line
do
        a=(`mgmt_cli -r true where-used name $line --format json | jq -r '."used-directly"[]' | grep name | grep -v SMC`)
        if [ -z "$a" ]; then
                echo "$line is not used in any group" | sed 's/"//g'
        else
                echo "$line is found in ${a[*]}" | sed 's/"name"//g' | sed 's/://g' | sed 's/"//g'
        fi
done &amp;lt; obj.csv
rm obj.csv&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample output&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cphost-1 is found in  cpgroup-1,
cphost-100 is found in  cpgroup-5,
cphost-2 is found in  cpgroup-1,  cpgroup-2,
cphost-200 is found in  cpgroup-5,
host_used_everywhere is found in  cpgroup-2,  cpgroup-5,  cpgroup-6,  cpgroup-3,  cpgroup-4,  cpgroup-1,
CP_default_Office_Mode_addresses_pool is not used in any group
cpnet_172.16.15.0-25 is found in  cpgroup-4,
IPv6_Link_Local_Hosts is not used in any group
net_10.20.10.0-24 is found in  cpgroup-1,&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 May 2022 19:02:23 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/how-to-find-in-which-groups-a-network-object-exists/m-p/148103#M6807</guid>
      <dc:creator>Alex-</dc:creator>
      <dc:date>2022-05-07T19:02:23Z</dc:date>
    </item>
  </channel>
</rss>

