<?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 Getting data from rules in show-access-rulebase when section headers are used in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Getting-data-from-rules-in-show-access-rulebase-when-section/m-p/194048#M8069</link>
    <description>&lt;P style="font-weight: 400;"&gt;When using show-access-rulebase with section headers, you might have issues parsing out the actual rules when section headers appear in the rulebase via a script with &lt;A href="https://jqlang.github.io/jq/" target="_self"&gt;jq&lt;/A&gt;.&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;The specific issue that rules are above all section headers (or there are no sections) are accessible with .rulebase[] while&amp;nbsp;rules below section headers are accessible with .rulebase[].rulebase[].&lt;BR /&gt;This creates a potential issue with scripting, since it's quite possible to have both in the same access layer.&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;How do you get only the access rules? You "flatten" it, which can be done with jq.&lt;BR /&gt;For example: &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;mgmt_cli -r true --format json show-access-rulebase name "$layerName" limit 500 | jq -r '. |recurse(.rulebase[]?) | select(.type == "access-rule")'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;For some context here:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;mgmt_cli -r true --format json show-access-rulebase name "$layerName" limit 500 &lt;/STRONG&gt;will show the first 500 rules in JSON format. You will need to &lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/API-How-to-get-all-objects-in-one-request/m-p/151122" target="_self"&gt;make multiple calls using limit/offset parameters&lt;/A&gt; to get additional results.&lt;/LI&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;jq -r&lt;/STRONG&gt; is used to parse the output of the mgmt_cli command to get the data you are interested in. To explain the argument we are passing to this command:
&lt;UL&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;recurse(.rulebase[]?)&lt;/STRONG&gt; &amp;nbsp;flattens the rulebase to a bunch of rulebase contents: access-rule, access-section, place-holder.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;select(.type == "access-rule")&lt;/STRONG&gt; filters the access-rules whose data we wish to access.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Oct 2023 15:46:52 GMT</pubDate>
    <dc:creator>PhoneBoy</dc:creator>
    <dc:date>2023-10-02T15:46:52Z</dc:date>
    <item>
      <title>Getting data from rules in show-access-rulebase when section headers are used</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Getting-data-from-rules-in-show-access-rulebase-when-section/m-p/194048#M8069</link>
      <description>&lt;P style="font-weight: 400;"&gt;When using show-access-rulebase with section headers, you might have issues parsing out the actual rules when section headers appear in the rulebase via a script with &lt;A href="https://jqlang.github.io/jq/" target="_self"&gt;jq&lt;/A&gt;.&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;The specific issue that rules are above all section headers (or there are no sections) are accessible with .rulebase[] while&amp;nbsp;rules below section headers are accessible with .rulebase[].rulebase[].&lt;BR /&gt;This creates a potential issue with scripting, since it's quite possible to have both in the same access layer.&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;How do you get only the access rules? You "flatten" it, which can be done with jq.&lt;BR /&gt;For example: &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;mgmt_cli -r true --format json show-access-rulebase name "$layerName" limit 500 | jq -r '. |recurse(.rulebase[]?) | select(.type == "access-rule")'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;For some context here:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;mgmt_cli -r true --format json show-access-rulebase name "$layerName" limit 500 &lt;/STRONG&gt;will show the first 500 rules in JSON format. You will need to &lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/API-How-to-get-all-objects-in-one-request/m-p/151122" target="_self"&gt;make multiple calls using limit/offset parameters&lt;/A&gt; to get additional results.&lt;/LI&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;jq -r&lt;/STRONG&gt; is used to parse the output of the mgmt_cli command to get the data you are interested in. To explain the argument we are passing to this command:
&lt;UL&gt;
&lt;LI style="font-weight: 400;"&gt;&lt;STRONG&gt;recurse(.rulebase[]?)&lt;/STRONG&gt; &amp;nbsp;flattens the rulebase to a bunch of rulebase contents: access-rule, access-section, place-holder.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;select(.type == "access-rule")&lt;/STRONG&gt; filters the access-rules whose data we wish to access.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 15:46:52 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Getting-data-from-rules-in-show-access-rulebase-when-section/m-p/194048#M8069</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2023-10-02T15:46:52Z</dc:date>
    </item>
  </channel>
</rss>

