<?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: API command to get the disable rule in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127932#M6178</link>
    <description>&lt;P&gt;Hi Sigbjorn,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get the rules which are already expired like we got for disabled rules from checkpoint rulebase.&lt;/P&gt;&lt;P&gt;Please let us know if any scripts for the same.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Aathi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Aug 2021 07:40:30 GMT</pubDate>
    <dc:creator>Aathi</dc:creator>
    <dc:date>2021-08-25T07:40:30Z</dc:date>
    <item>
      <title>API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/87363#M4937</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the disabled rules in checkpoint rule base by using API or mgmt_cli commands , the way we are getting the zero hit count rule.&lt;/P&gt;&lt;P&gt;can you share the command to get the disabled rules from rulebases.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Aathi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 04:45:29 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/87363#M4937</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2020-06-05T04:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/87371#M4938</link>
      <description>There is not a specific API to retrieve disabled rules.&lt;BR /&gt;However, you can retrieve the rulebase via mgmt_cli and use jq to filter the results using a select statement.</description>
      <pubDate>Fri, 05 Jun 2020 05:40:01 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/87371#M4938</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2020-06-05T05:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97277#M5177</link>
      <description>&lt;P&gt;Hi PhoneBoy,&lt;/P&gt;&lt;P&gt;By using Jq filter i got the UID and also .i need to get the Source ,destination and port as well( need to get the exact rulebase&amp;nbsp; by using UID or something) .is it possible to get those.if yes can you please share the exact syntax for the same.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 12:03:56 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97277#M5177</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2020-09-22T12:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97316#M5178</link>
      <description>&lt;P&gt;What CLI do you have so far?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 20:48:01 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97316#M5178</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2020-09-22T20:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97328#M5179</link>
      <description>&lt;P&gt;Quick Powershell example code to extract the disabled rules.&lt;/P&gt;&lt;P&gt;As for the actual source/destination/service, these are UID's of the actual object, so you would need to do another query in the foreach loop to resolve them to names if that's what you're looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[string]$BaseUri = "https://10.10.1.1/web_api"
[string]$domain = "Domainname"  # Only used for MDS servers
[string]$user = "username"
[string]$pass = "password"

$loginData = @{
    "user" = $user
    "password" = $pass
    "domain" = $domain # Only used for MDS servers
} | ConvertTo-Json

Write-Output "Invoking Login"
$login = Invoke-RestMethod -Method Post -Uri "$BaseUri/login" -Body $loginData -Headers @{ "content-type" = "application/json" }

$headers = @{
    "content-type" = "application/json"
    "x-chkp-sid" = $login.sid
}



# Get RuleBase
Write-Output "Getting rulebase"
$body = @{
    "name" = "demo-policy Network"
    } | ConvertTo-Json
$rules = Invoke-RestMethod -Method Post -Uri "$BaseUri/show-access-rulebase" -Body $body -Headers $headers

foreach ($i in $rules.rulebase.rulebase) {  
    if ($i.enabled -like "False") {
        Write-Output "Rulename: $($i.name), Source: $($i.source), Destination: $($i.destination), Service: $($i.service), Enabled: $($i.enabled)"
        }
}


Write-Output "Disconnect session $($login.uid)"
$null = Invoke-RestMethod -Method Post -Uri "$BaseUri/disconnect" -Headers $headers -Body (@{ "uid" = $login.uid } | ConvertTo-Json)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Sep 2020 06:56:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97328#M5179</guid>
      <dc:creator>Sigbjorn</dc:creator>
      <dc:date>2020-09-23T06:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97336#M5180</link>
      <description>&lt;P&gt;Hi Phoneboy.&lt;/P&gt;&lt;P&gt;Its Mgmt_cli.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 09:07:35 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97336#M5180</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2020-09-23T09:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97697#M5192</link>
      <description>&lt;P&gt;Hi Sigbjorn,&lt;/P&gt;&lt;P&gt;i tried to get source name and destination name and service using for each&amp;nbsp; loop but getting the error,can you share the exact syntax to get the same.&lt;/P&gt;&lt;P&gt;Thanks in advance.&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;</description>
      <pubDate>Mon, 28 Sep 2020 10:25:21 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97697#M5192</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2020-09-28T10:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97699#M5193</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This should do it:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;# Get RuleBase
Write-Output "Getting rulebase"
$body = @{
    "name" = $layer
    } | ConvertTo-Json
$rules = Invoke-RestMethod -Method Post -Uri "$BaseUri/show-access-rulebase" -Body $body -Headers $headers

foreach ($y in $rules.rulebase.rulebase) {  
        $body = @{
        "uid" = $($y.uid)
        "layer" = $layer
        } |ConvertTo-Json
        $rule = Invoke-RestMethod -Method Post -Uri "$BaseUri/show-access-rule" -Body $body -Headers $headers
        if ($($rule.enabled) -like "False") {
            Write-output "Disabled rule, Rulename: $($rule.name), Enabled: $($rule.enabled), Rule UID: $($rule.uid), Source: $($rule.source.Name), Destination: $($rule.destination.Name), Service: $($rule.service.Name), Action: $($rule.action.Name)"
            }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:55:24 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97699#M5193</guid>
      <dc:creator>Sigbjorn</dc:creator>
      <dc:date>2020-09-28T11:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97816#M5198</link>
      <description>&lt;P&gt;Here is a mgmt_cli API call you can try. I modified it from a call I use to grab zero hits rules. If you are not running a multi-domain management server you can remove the -d option. This will send the results to a csv file as well. You may be having the problem retrieving source and destination if they have more than one object. the [] specifies those fields are arrays. The one limitation I haven't been able to get around is those fields return UID values rather than their plain text names.&lt;/P&gt;&lt;P&gt;mgmt_cli -d &amp;lt;domain&amp;gt; show access-rulebase offset 0 limit 2000 uid "&amp;lt;rulebase UID&amp;gt;" details-level "standard" use-object-dictionary true --format json -u &amp;lt;username&amp;gt; |jq -r '.rulebase[].rulebase[]|select(.enabled = "False")| [."uid", ."name", ."comments", ."enabled", .source[], .destination[], .service[]]|@csv' &amp;gt; &amp;lt;csvfilename&amp;gt;.csv&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ron&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:14:33 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/97816#M5198</guid>
      <dc:creator>REDW0LF</dc:creator>
      <dc:date>2020-09-29T15:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126016#M6137</link>
      <description>&lt;P&gt;Hi REDWOLF,&lt;/P&gt;&lt;P&gt;Thanks for the update.i tried but getting below error can you help on this&lt;/P&gt;&lt;P&gt;[Expert@XXX:0]# mgmt_cli show access-rulebase offset 0 limit 2000 uid "cafc790f-681d-49ea-b44c-b618dc937c66" details-level "standard" use-object-dictionary true --format json -u admin|jq -r '.rulebase[].rulebase[]|select(.enabled = "False")| [."uid", ."name", ."comments", ."enabled", .source[], .destination[], .service[]]|@csv' &amp;gt; aathi.csv&lt;BR /&gt;Password:&lt;/P&gt;&lt;P&gt;jq: error: Cannot iterate over null&lt;/P&gt;&lt;P&gt;can u help on this&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 08:14:08 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126016#M6137</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2021-08-09T08:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126046#M6138</link>
      <description>&lt;P&gt;Hi SIG,&lt;/P&gt;&lt;P&gt;Thank you so much for sharing the script.&lt;/P&gt;&lt;P&gt;This script only check the first 50 rules from rulebase ,is there any way to check all the rulebases&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 12:49:55 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126046#M6138</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2021-08-09T12:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126068#M6139</link>
      <description>&lt;P&gt;The API only returns a limited number of results by design.&lt;BR /&gt;That is true even if you specify a higher limit in the API call.&lt;BR /&gt;You would have to make multiple calls to the same API using the offset parameter iteratively to get all the results.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 15:17:43 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/126068#M6139</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2021-08-09T15:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127686#M6163</link>
      <description>&lt;P&gt;Hi Sigbjorn,&lt;/P&gt;&lt;P&gt;Thanks for sharing the scripts.Can you help us to get the&amp;nbsp; already expired Rule base list.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 10:39:51 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127686#M6163</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2021-08-23T10:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127703#M6164</link>
      <description>&lt;P&gt;Hi Aathi, I'm not entirely sure what you're looking for.&lt;/P&gt;
&lt;P&gt;Could you elaborate?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 14:15:03 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127703#M6164</guid>
      <dc:creator>Sigbjorn</dc:creator>
      <dc:date>2021-08-23T14:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127737#M6165</link>
      <description>&lt;P&gt;That means there's an error in the jq statement.&lt;BR /&gt;You've got .rulebase[] in there twice.&lt;BR /&gt;Also it looks like the select doesn't do what you want.&lt;BR /&gt;Most of the results return a UID, which I assume you want in some sort of human readable format.&lt;BR /&gt;Also, setting the limit to 2000 will not return all results, you will need to make multiple calls using the offset parameter to get the next 50 results (or so).&lt;BR /&gt;Not exactly right, but this is a lot closer:&lt;/P&gt;
&lt;P class="p1 lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;mgmt_cli -s sid.txt show access-rulebase name "LayerName" details-level full --format json | jq -r '.rulebase[] | select (.enabled == false)| .uid' | while read X;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;do&lt;BR /&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;mgmt_cli -s sid.txt --format json show access-rule uid $X layer "LayerName" |&lt;BR /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; &amp;nbsp; jq -r '[.uid, .name, .source[].name, .destination[].name, .service[].name, .action.name]|@csv'&lt;BR /&gt;done&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="p1"&gt;At a high level, this is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI class="p1"&gt;Getting the UID of the rules that are disabled (note you will need to use limit/offset in this command and call it multiple times to get all the rules.&lt;/LI&gt;
&lt;LI class="p1"&gt;For each rule UID, get human readable source/destination/service/action and output in something that looks like a CSV file (though each source/destination/service will create a column).&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There may be some way to clean up the jq further here so you get a cleaner CSV file.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 21:44:24 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127737#M6165</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2021-08-23T21:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: API command to get the disable rule</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127932#M6178</link>
      <description>&lt;P&gt;Hi Sigbjorn,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get the rules which are already expired like we got for disabled rules from checkpoint rulebase.&lt;/P&gt;&lt;P&gt;Please let us know if any scripts for the same.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Aathi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 07:40:30 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/API-command-to-get-the-disable-rule/m-p/127932#M6178</guid>
      <dc:creator>Aathi</dc:creator>
      <dc:date>2021-08-25T07:40:30Z</dc:date>
    </item>
  </channel>
</rss>

