<?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 Checking a list of IP's for Host Objects; Add or Set Group Membership in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Checking-a-list-of-IP-s-for-Host-Objects-Add-or-Set-Group/m-p/40960#M2790</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This was born out of a one-off&amp;nbsp;customer request that I thought would serve as a good example for how to use a query to provide if/then results.&amp;nbsp;The customer&amp;nbsp;really wanted to do this in bash and not have to work in python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use Case:&lt;/P&gt;&lt;P&gt;The customer wanted to be able to take a txt file with IPv4 Address in it and do a check on each IP to see if a host object already existed. If the object already existed they wanted to create a 'set' command to assign it to a group. If the IP did not exist under a host object they wanted to create the host object using a generic name and assign it to the same group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can find the full script here:&amp;nbsp;&lt;A class="link-titled" href="https://github.com/WadesWeaponShed/IP-List-Host-Check-Add-or-Set" title="https://github.com/WadesWeaponShed/IP-List-Host-Check-Add-or-Set"&gt;GitHub - WadesWeaponShed/IP-List-Host-Check-Add-or-Set&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The meat of the script is below; Using if statements we search the object database and if the search returns an object [1] then we issue the set command for it, if the search returns nothing [0] then we build the add command for the host.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;printf "\nChecking For Existing Hosts\n"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;for line in $(cat ip.txt)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if [[ $(mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json |jq '.total') = 1 ]]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json | jq --raw-output '.objects[] | "mgmt_cli -s id.txt set host name " +.name + " groups auto-group"' &amp;gt;&amp;gt; host_set.txt&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif [[ $(mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json |jq '.total') = 0 ]]; then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf "mgmt_cli -s id.txt add host name Host-$line ip-address $line groups auto-group\n" &amp;gt;&amp;gt; host_set.txt&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi&lt;BR /&gt;&amp;nbsp; done&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Feb 2019 16:07:31 GMT</pubDate>
    <dc:creator>Adam_Forester</dc:creator>
    <dc:date>2019-02-15T16:07:31Z</dc:date>
    <item>
      <title>Checking a list of IP's for Host Objects; Add or Set Group Membership</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Checking-a-list-of-IP-s-for-Host-Objects-Add-or-Set-Group/m-p/40960#M2790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This was born out of a one-off&amp;nbsp;customer request that I thought would serve as a good example for how to use a query to provide if/then results.&amp;nbsp;The customer&amp;nbsp;really wanted to do this in bash and not have to work in python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use Case:&lt;/P&gt;&lt;P&gt;The customer wanted to be able to take a txt file with IPv4 Address in it and do a check on each IP to see if a host object already existed. If the object already existed they wanted to create a 'set' command to assign it to a group. If the IP did not exist under a host object they wanted to create the host object using a generic name and assign it to the same group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can find the full script here:&amp;nbsp;&lt;A class="link-titled" href="https://github.com/WadesWeaponShed/IP-List-Host-Check-Add-or-Set" title="https://github.com/WadesWeaponShed/IP-List-Host-Check-Add-or-Set"&gt;GitHub - WadesWeaponShed/IP-List-Host-Check-Add-or-Set&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The meat of the script is below; Using if statements we search the object database and if the search returns an object [1] then we issue the set command for it, if the search returns nothing [0] then we build the add command for the host.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;printf "\nChecking For Existing Hosts\n"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;for line in $(cat ip.txt)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if [[ $(mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json |jq '.total') = 1 ]]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json | jq --raw-output '.objects[] | "mgmt_cli -s id.txt set host name " +.name + " groups auto-group"' &amp;gt;&amp;gt; host_set.txt&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif [[ $(mgmt_cli -r true -d $DOMAIN show objects type host filter "$line" ip-only true offset $I limit 500 --format json |jq '.total') = 0 ]]; then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf "mgmt_cli -s id.txt add host name Host-$line ip-address $line groups auto-group\n" &amp;gt;&amp;gt; host_set.txt&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi&lt;BR /&gt;&amp;nbsp; done&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Feb 2019 16:07:31 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Checking-a-list-of-IP-s-for-Host-Objects-Add-or-Set-Group/m-p/40960#M2790</guid>
      <dc:creator>Adam_Forester</dc:creator>
      <dc:date>2019-02-15T16:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Checking a list of IP's for Host Objects; Add or Set Group Membership</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Checking-a-list-of-IP-s-for-Host-Objects-Add-or-Set-Group/m-p/61797#M3858</link>
      <description>&lt;P&gt;I see the limit is set to 500 in script, does this mean it will only handle the first 500 hosts??&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 20:04:07 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Checking-a-list-of-IP-s-for-Host-Objects-Add-or-Set-Group/m-p/61797#M3858</guid>
      <dc:creator>Juan_Concepcion</dc:creator>
      <dc:date>2019-09-03T20:04:07Z</dc:date>
    </item>
  </channel>
</rss>

