<?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: RulebaseExporter/RulebaseImporter in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39129#M2435</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The developed way we provide to get more than 500 of anything is to use the offset limit key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the json object that is returned, there are three keys that allow you to programmaticly control whether to pull more data or not.&lt;/P&gt;&lt;P&gt;They are the from, to and total keys. Essentially until to == total, you would increase the offset key in your request by your limit and keep pulling data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have python only examples but there are other tools in Code Hub with examples reference points on how to work with these in shell! (&lt;A _jive_internal="true" class="jivelink11" href="https://community.checkpoint.com/docs/DOC-1911" title="https://community.checkpoint.com/docs/DOC-1911"&gt;https://community.checkpoint.com/docs/DOC-1911&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;I've seen as low as 20 rules at a time surpass 20 minute extended Web API timeouts, so it's just something to be mindful of!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best of luck on your continued work on this.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Oct 2018 22:10:29 GMT</pubDate>
    <dc:creator>Joshua_Hatter</dc:creator>
    <dc:date>2018-10-23T22:10:29Z</dc:date>
    <item>
      <title>RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39126#M2432</link>
      <description>&lt;P&gt;Hello Checkmates!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote those two tools for one of my projects. I wanted to have an easy way of rulebases migration from Managment to management IE: Lab to prod, prod to lab... To do so, I leverage some&amp;nbsp;useful and quick API calls:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example, the call:“&lt;SPAN style="color: #3366ff;"&gt;show access-rulebase name "RulebaseName" details-level full&lt;/SPAN&gt;”&amp;nbsp;will return&amp;nbsp;the whole rulebase. The json output will contain all objects(objects-dictionary[]) and rules(rulebase[]).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once we have the JSON in hand, we can then execute query on it using "jq".&amp;nbsp; This means fewer API calls are sent&amp;nbsp;to the management server. Less API calls mean more speed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;STRONG&gt;Here some "jq" queries examples:&lt;/STRONG&gt;&lt;/H1&gt;
&lt;P&gt;&lt;STRONG&gt;This is the command to list all available layers name inside current management.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;First we get the JSON file by sending this one API call:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;mgmt_cli show access-rulebases --session-id "$session_id" –format json &amp;gt; access-layers.json&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here the JQ query&amp;nbsp;to get all layers name:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #0000ff;"&gt;cat access-layers.json | jq '."access-layers"[]|.name'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&lt;STRONG&gt;This is the command To get the rulebase JSON:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="color: #3366ff;"&gt;mgmt_cli show access-rulebase name “$LayerName” --session-id "$session_id" –format json&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&lt;STRONG&gt;JQ query examples to work on that rulebase:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;This will show all information for the access-layer Network:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat Network.json | jq ‘.”rulebase”[]’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;This will show information on rule number 12:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat Network.json | jq ‘.”rulebase”[12]’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;This will show the Sources of rule number 12:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat Network,json |&amp;nbsp;jq ‘.”rulebase”[12]|.source’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&lt;STRONG&gt;This will show all objects by this rulebase:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat network.json | jq ‘.”objects-dictionary”[]’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&lt;STRONG&gt;You can then search for object name, UID, type like this:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&lt;STRONG&gt;This show information of object name R80GW:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="color: #3366ff;"&gt;cat network.json | jq ‘.”objects-dictionary”[]|select (.name== “’R80GW’”)’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;This show information of object UID&amp;nbsp;aedb0f7c-c5f4-4f07-bad0-9e29200041dc:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat network.json | jq ‘.”objects-dictionary”[]|select (.uid== “’aedb0f7c-c5f4-4f07-bad0-9e29200041dc’”)’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;This will show all host in dictionary:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #3366ff;"&gt;cat network.json | jq ‘.”objects-dictionary”[]|select (.type== “’host”)’&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage of using JSON and JQ: the export is fast. Don’t need to query the management for every single object. Just one API call gets the full rulebase and objects. All other processing is done locally using “jq” and the received json file. Objects that are not used by the rulebase won’t be exported.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Base on this principle, I created those two scripts. RulebaseExporter.sh and RulebaseImporter.sh.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Usage:&lt;/H1&gt;
&lt;P&gt;Run the exporter script in an empty folder on your Source management server. It will extract all layers from that management server and create a "tar" file.&lt;/P&gt;
&lt;P&gt;Copy the TAR archive in an empty folder on the destination Management server. Untar and run RulebaseImporter. It will process all available layers and create the required objects on this management server.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are in a domain, provide the CMA name you want to export on the source Managment. On the target management, create an empty CMA then run the Importer and login to that empty CMA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Supported Objects Types:&lt;/H1&gt;
&lt;P&gt;My scripts currently support those objects types:&lt;/P&gt;
&lt;UL style="list-style-type: circle;"&gt;
&lt;LI&gt;Access-Rulebase&lt;/LI&gt;
&lt;LI&gt;Access-Layers&lt;/LI&gt;
&lt;LI&gt;Inline layers&lt;/LI&gt;
&lt;LI&gt;Section Titles&lt;/LI&gt;
&lt;LI&gt;Network Objects:
&lt;UL&gt;
&lt;LI&gt;Host&lt;/LI&gt;
&lt;LI&gt;Network&lt;/LI&gt;
&lt;LI&gt;Address-Range&lt;/LI&gt;
&lt;LI&gt;Group&lt;/LI&gt;
&lt;LI&gt;Service-Group&lt;/LI&gt;
&lt;LI&gt;service tcp&lt;/LI&gt;
&lt;LI&gt;service utp&lt;/LI&gt;
&lt;LI&gt;Application Categories (system created)&lt;/LI&gt;
&lt;LI&gt;Application object (system created)&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Login MDM CMA&lt;/LI&gt;
&lt;LI&gt;Login to standard Management server&lt;/LI&gt;
&lt;LI&gt;Action
&lt;UL&gt;
&lt;LI&gt;Accept&lt;/LI&gt;
&lt;LI&gt;Drop&lt;/LI&gt;
&lt;LI&gt;Inline-layer&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Enable/Disable rule&lt;/LI&gt;
&lt;LI&gt;Rule name&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TODO:&amp;nbsp;NAT policies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notepad ++ required &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy scripting!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the full list of White Papers, &lt;A href="https://community.checkpoint.com/t5/General-Topics/White-Papers-Publishing-Project/m-p/53242#M10603" target="_blank"&gt;go here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 12:32:14 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39126#M2432</guid>
      <dc:creator>Nicolas_Boisse</dc:creator>
      <dc:date>2019-07-08T12:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39127#M2433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am quickly reading over the exporter and I have some feedback!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Appears this only works for &amp;lt; 500 rules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You get 500 objects at a time with full-details, in large environments these commands can fail due to mgmt_cli timeout of 3 minutes.&lt;/P&gt;&lt;P&gt;We would typically suggest getting less objects maybe 50 at a time, and using offset to get the 'next' 50 until all objects are read.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2018 20:14:33 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39127#M2433</guid>
      <dc:creator>Joshua_Hatter</dc:creator>
      <dc:date>2018-10-23T20:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39128#M2434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua, thanks for your feedback. Its in my plan to process the export with less objects at a time using the from to variables. I found a way to overcome this limitation though by using section titles. if you have a rulebase of 500 rules, adding a section titles in the middle will give you two sets of 250 rules. In the main policy you will see 2 rules in the main index (.rulebase[]). To be tested...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did't hit the 3 minutes time out on my tests. My larger test though was 1 policy with 100 rules, 1 inline layer per rule&amp;nbsp; with 3 rules per layer. this give 300 rules.&amp;nbsp; It took 15 seconds&amp;nbsp; to export everything on a 2 core management VM running on my laptop:&lt;IMG __jive_id="71990" class="image-1 jive-image" src="https://community.checkpoint.com/legacyfs/online/checkpoint/71990_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More to come &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2018 21:06:58 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39128#M2434</guid>
      <dc:creator>Nicolas_Boisse</dc:creator>
      <dc:date>2018-10-23T21:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39129#M2435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The developed way we provide to get more than 500 of anything is to use the offset limit key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the json object that is returned, there are three keys that allow you to programmaticly control whether to pull more data or not.&lt;/P&gt;&lt;P&gt;They are the from, to and total keys. Essentially until to == total, you would increase the offset key in your request by your limit and keep pulling data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have python only examples but there are other tools in Code Hub with examples reference points on how to work with these in shell! (&lt;A _jive_internal="true" class="jivelink11" href="https://community.checkpoint.com/docs/DOC-1911" title="https://community.checkpoint.com/docs/DOC-1911"&gt;https://community.checkpoint.com/docs/DOC-1911&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;I've seen as low as 20 rules at a time surpass 20 minute extended Web API timeouts, so it's just something to be mindful of!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best of luck on your continued work on this.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2018 22:10:29 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39129#M2435</guid>
      <dc:creator>Joshua_Hatter</dc:creator>
      <dc:date>2018-10-23T22:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39130#M2436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joshua, I agree with you, there is always a place for improvements and I will add this in a future release. Maybe on the version 2 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;For that first version, I wanted to have only 1 json file per policy package/layers.&amp;nbsp; Then I work on the JSON&amp;nbsp;with jq to rebuild the policy. It's easier to process on my importer script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;20 rules more than 20 minutes seems a very long time to my hears. In the RulebaseExporters example, I only use this API:"show access-rulebase name "rulebasebame" --format json details-level full" to get the full rulebase. This API call didn't take very long to run on all my tests. So I don't understand why it took so long on your example. Can you share a screenshot to my Checkpoint mail&amp;nbsp; so I can better understand that particular case? Or can you run the ExporterTool on that management to see how long it take?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you tried my exporter script? My last test took 13,36 sec for a 28 rules policy from my production rulebase VM(2 cores only vm). Around 15 sec for 300 rules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My intend is to have something&amp;nbsp;quick and easy to use. This is what my script does.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your feed back &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2018 23:11:18 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39130#M2436</guid>
      <dc:creator>Nicolas_Boisse</dc:creator>
      <dc:date>2018-10-23T23:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39131#M2437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It was a very specific case of course. I haven't run the tool yet.&lt;/P&gt;&lt;P&gt;Just pointing out some things to help where others have also run into this issue, including myself!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2018 12:48:13 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/39131#M2437</guid>
      <dc:creator>Joshua_Hatter</dc:creator>
      <dc:date>2018-10-24T12:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/112494#M5656</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Would this script work for me to export from a R80.10 server and import this information into a R80.40 server?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:38:09 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/112494#M5656</guid>
      <dc:creator>bryanastudillo</dc:creator>
      <dc:date>2021-03-04T21:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: RulebaseExporter/RulebaseImporter</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/118335#M5844</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the script, apparently the export finishes fine but when I import the rulebase I get no rules, when I check the rulebase file I get an error "Timeout was reached"&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 15:26:15 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/RulebaseExporter-RulebaseImporter/m-p/118335#M5844</guid>
      <dc:creator>bryanastudillo</dc:creator>
      <dc:date>2021-05-13T15:26:15Z</dc:date>
    </item>
  </channel>
</rss>

