<?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: &amp;quot;policyCleanUp.py&amp;quot; - OverflowError in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8684#M712</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of all; thanks for getting back to me Joshua &amp;amp; Amiad.&lt;/P&gt;&lt;P&gt;Amiad, initially I wanted to answer you via mail as we discussed but I think this information is useful for the whole community. After a little research I found out what the initial cause of the bug is. I was not aware that your script takes use of the custom field option that each customer can configure individually. So to summarize it, the script has default values for disabling and/or deleting rules. Those values are set to 180 days per default. In addition to that it is possible to override the values via parameters, that can be included at the execution time (--disable-after and --delete-after). This is absolutely fine and a very good idea.&lt;/P&gt;&lt;P&gt;But there is more...&lt;STRONG&gt; the third override possibility&lt;/STRONG&gt; is checked per each rule. Here the script looks at the value of custom-fields, field 1 to be precise. If the value of this field is an integer it uses this value instead of the "default 180 days" AND instead of the parameter values of&amp;nbsp;&lt;SPAN&gt;--disable-after and --delete-after:&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE data-tab-size="8" style="color: #24292e; background-color: #ffffff; width: 758px;"&gt;&lt;TBODY&gt;&lt;TR style="height: 50px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 50px; width: 718px;"&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;Beginning at line 212 as per current GitHub version:&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Get rule's thresholds.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Disable and deleted thresholds are calculated by global thresholds or overrides thresholds (local override).&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Local thresholds- user can override the global thresholds by adding number to custom-fields per rule.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #d73a49;"&gt;def&lt;/SPAN&gt; &lt;SPAN class="" style="color: #6f42c1;"&gt;get_rule_final_threshold&lt;/SPAN&gt;(&lt;SPAN class="" style="color: #24292e;"&gt;rule&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;field&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;threshold_type&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;global_thresholds&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# &lt;STRONG&gt;Custom-field1 contains override for disable threshold&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;local_threshold &lt;SPAN class="" style="color: #d73a49;"&gt;=&lt;/SPAN&gt; rule.get(&lt;SPAN class="" style="color: #032f62;"&gt;'custom-fields'&lt;/SPAN&gt;, {}).get(field)&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# -1 represents a rule that should be skipped all time.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The interesting part about this procedure is that there aren't any ways to avoid the override by custom field option (maybe option is the wrong word, as it really is not optional). In the environment where I tested the script the custom field contains the date when the rule was checked via dual control principle. The content of the custom field for a rule which was checked on the 1st of February 2019 would contain the value "20190201" - this translated to the integer reading process of the script would lead to 20.190.201 days, resulting in the OverFlow error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition to that it seems like the script does not read all the rules from a given policy package, but this could be a result due to the just mentioned threshold override.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe I am blind, but is there a possibility to run this script just with parameter or default values regarding the disable/delete time? If not, is there any reason to not include one? And why is the script referencing to custom-fields at all? Don't misunderstand me, this can be very convinient to handle each rule on its own, but it is simply not a script that can be shared with the community in such a case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any reply and hint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Maik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Mar 2019 13:13:49 GMT</pubDate>
    <dc:creator>Maik</dc:creator>
    <dc:date>2019-03-06T13:13:49Z</dc:date>
    <item>
      <title>"policyCleanUp.py" - OverflowError</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8681#M709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This thread is especially targeted to the python community and also to the employees who wrote the &lt;A href="https://github.com/CheckPointSW/PolicyCleanUp"&gt;policyCleanUp python script&lt;/A&gt;. Yesterday I found out that this script exists, so I wanted to give it a try within a lab environment with test data. The rules here actually have a hit count present, some of them do not have any hits at all. So it seems to be a good place to get a first perspective of the output and actual result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However; I noticed a few things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. A shebang line for the respective GAiA version - if you run the script locally on the SMS - would help to run it more easily. That's no problem and could be added.&lt;/P&gt;&lt;P&gt;2. The first execution threw the following error:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;admin@myLabSMS:~/Scripts/policyCleanUp# ./policyCleanUp.py&lt;BR /&gt; File "./policyCleanUp.py", line 324&lt;BR /&gt;SyntaxError: Non-ASCII character '\xe2' in file ./policyCleanUp.py on line 324, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for deta ils&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This issue could be solved by specifying a different coding type like for example utf-8.&lt;/P&gt;&lt;P&gt;3. After that the execution - unrelated to any given parameters - ends with the following error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;admin@&lt;SPAN style="background-color: #f6f6f6;"&gt;myLabSMS&lt;/SPAN&gt;:~/Scripts/policyCleanUp# ./policyCleanUp.py -k "POL_Test_Package" -u admin -p &amp;lt;MySecretPassword&amp;gt;&lt;/P&gt;&lt;P&gt;[2019-03-01 12:41:08] Plan&lt;BR /&gt;[2019-03-01 12:41:09] Validate targets&lt;BR /&gt;[2019-03-01 12:41:14] Package &lt;SPAN style="background-color: #f6f6f6;"&gt;POL_Test_Package&lt;/SPAN&gt;&lt;BR /&gt;[2019-03-01 12:41:14] Layer &lt;SPAN style="background-color: #f6f6f6;"&gt;POL_Test_Package&lt;/SPAN&gt; Network&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt; File "./policyCleanUp.py", line 1120, in &amp;lt;module&amp;gt;&lt;BR /&gt; main()&lt;BR /&gt; File "./policyCleanUp.py", line 1050, in main&lt;BR /&gt; if rule_should_be_disabled(rule, global_thresholds) is True:&lt;BR /&gt; File "./policyCleanUp.py", line 853, in rule_should_be_disabled&lt;BR /&gt; &lt;SPAN style="font-family: tahoma, arial, helvetica, sans-serif;"&gt;&lt;STRONG&gt;if rule_last_hit_time + datetime.timedelta(days=final_disable_threshold) &amp;lt; DATETIME_NOW:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;OverflowError: date value out of range&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This could also be resolved by someone who did not write the script, but my guess was that I am not the only one who experiences this issue. In addition to that; I am using the latest &lt;A href="https://github.com/CheckPointSW/cp_mgmt_api_python_sdk#download-the-repository"&gt;Python SDK from here&lt;/A&gt; and changed the OS variable as stated there. The GAiA version is R80.20 GA (not a special M Release).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Community; is there anyone who already used this script? Did you run into the above (or other) errors and if yes - how did you solve them?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Check Point; maybe someone from the actual script authors can verify the above error in order to verify the script functionality.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and regards,&lt;/P&gt;&lt;P&gt;Maik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 12:16:55 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8681#M709</guid>
      <dc:creator>Maik</dc:creator>
      <dc:date>2019-03-01T12:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: "policyCleanUp.py" - OverflowError</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8682#M710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is your DEFAULT_DISABLE_THRESHOLD set to, default(180)?&lt;/P&gt;&lt;P&gt;Best I can do is to simply debug this, can you modify the rule_should_be_disabled function to include the following.&lt;/P&gt;&lt;P&gt;Potentially &lt;A href="https://community.checkpoint.com/migrated-users/2192"&gt;Amiad Stern&lt;/A&gt;‌ might have a better idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;def rule_should_be_disabled(rule, global_thresholds):      global DATETIME_NOW      # Calculate final thresholds     final_disable_threshold = get_rule_final_threshold(rule, 'field-1', 'disable', global_thresholds)     if final_disable_threshold is None:         return False      # Get rule last hit time     rule_last_hit_time = get_rule_last_hit_time(rule)      # Disable rule - no hits too long     try:         if rule_last_hit_time + datetime.timedelta(days=final_disable_threshold) &amp;lt; DATETIME_NOW:             return True     except OverflowError:         print_msg("Last Hit: {}".format(rule_last_hit_time))         print_msg("Disable Threshold: {}".format(datetime.timedelta(days=final_disable_threshold)))         raise      return False&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 15:42:22 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8682#M710</guid>
      <dc:creator>Joshua_Hatter</dc:creator>
      <dc:date>2019-03-01T15:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: "policyCleanUp.py" - OverflowError</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8683#M711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.checkpoint.com/migrated-users/57462"&gt;Maik Dummer&lt;/A&gt;‌ ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your feedback.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We will address items #1 and #2 on Sunday.&lt;/P&gt;&lt;P&gt;As for item #3 we didn't encounter it during our tests (and it was tested on real large setups),&amp;nbsp; i would like to track this issue fast, can you please contact me on &lt;A href="mailto:amiads@checkpoint.com"&gt;amiads@checkpoint.com&lt;/A&gt;&amp;nbsp;so we can continue investigate it offline?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amiad.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 18:53:51 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8683#M711</guid>
      <dc:creator>Amiad_Stern</dc:creator>
      <dc:date>2019-03-01T18:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: "policyCleanUp.py" - OverflowError</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8684#M712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of all; thanks for getting back to me Joshua &amp;amp; Amiad.&lt;/P&gt;&lt;P&gt;Amiad, initially I wanted to answer you via mail as we discussed but I think this information is useful for the whole community. After a little research I found out what the initial cause of the bug is. I was not aware that your script takes use of the custom field option that each customer can configure individually. So to summarize it, the script has default values for disabling and/or deleting rules. Those values are set to 180 days per default. In addition to that it is possible to override the values via parameters, that can be included at the execution time (--disable-after and --delete-after). This is absolutely fine and a very good idea.&lt;/P&gt;&lt;P&gt;But there is more...&lt;STRONG&gt; the third override possibility&lt;/STRONG&gt; is checked per each rule. Here the script looks at the value of custom-fields, field 1 to be precise. If the value of this field is an integer it uses this value instead of the "default 180 days" AND instead of the parameter values of&amp;nbsp;&lt;SPAN&gt;--disable-after and --delete-after:&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE data-tab-size="8" style="color: #24292e; background-color: #ffffff; width: 758px;"&gt;&lt;TBODY&gt;&lt;TR style="height: 50px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 50px; width: 718px;"&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;Beginning at line 212 as per current GitHub version:&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Get rule's thresholds.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Disable and deleted thresholds are calculated by global thresholds or overrides thresholds (local override).&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# Local thresholds- user can override the global thresholds by adding number to custom-fields per rule.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #d73a49;"&gt;def&lt;/SPAN&gt; &lt;SPAN class="" style="color: #6f42c1;"&gt;get_rule_final_threshold&lt;/SPAN&gt;(&lt;SPAN class="" style="color: #24292e;"&gt;rule&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;field&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;threshold_type&lt;/SPAN&gt;, &lt;SPAN class="" style="color: #24292e;"&gt;global_thresholds&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# &lt;STRONG&gt;Custom-field1 contains override for disable threshold&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;local_threshold &lt;SPAN class="" style="color: #d73a49;"&gt;=&lt;/SPAN&gt; rule.get(&lt;SPAN class="" style="color: #032f62;"&gt;'custom-fields'&lt;/SPAN&gt;, {}).get(field)&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 25px;"&gt;&lt;TD class="" style="color: #24292e; padding: 0px 10px; height: 25px; width: 718px;"&gt;&lt;SPAN class="" style="color: #6a737d;"&gt;# -1 represents a rule that should be skipped all time.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The interesting part about this procedure is that there aren't any ways to avoid the override by custom field option (maybe option is the wrong word, as it really is not optional). In the environment where I tested the script the custom field contains the date when the rule was checked via dual control principle. The content of the custom field for a rule which was checked on the 1st of February 2019 would contain the value "20190201" - this translated to the integer reading process of the script would lead to 20.190.201 days, resulting in the OverFlow error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition to that it seems like the script does not read all the rules from a given policy package, but this could be a result due to the just mentioned threshold override.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe I am blind, but is there a possibility to run this script just with parameter or default values regarding the disable/delete time? If not, is there any reason to not include one? And why is the script referencing to custom-fields at all? Don't misunderstand me, this can be very convinient to handle each rule on its own, but it is simply not a script that can be shared with the community in such a case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any reply and hint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Maik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2019 13:13:49 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/8684#M712</guid>
      <dc:creator>Maik</dc:creator>
      <dc:date>2019-03-06T13:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: "policyCleanUp.py" - OverflowError</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/46741#M3143</link>
      <description>&lt;P&gt;Hello Amiad,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you already have time to check my response?&lt;/P&gt;&lt;P&gt;Thanks and best regards,&lt;/P&gt;&lt;P&gt;Maik&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:22:44 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-policyCleanUp-py-quot-OverflowError/m-p/46741#M3143</guid>
      <dc:creator>Maik</dc:creator>
      <dc:date>2019-03-13T12:22:44Z</dc:date>
    </item>
  </channel>
</rss>

