<?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 SmartTask output contains non-printable characters in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243842#M8978</link>
    <description>&lt;P&gt;Sooo... I guess this is normal?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-03-14 at 5.47.44 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/29917i5AF1D33705696033/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-03-14 at 5.47.44 PM.png" alt="Screenshot 2025-03-14 at 5.47.44 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Test script is just a simplistic one to get started:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#!/bin/bash
cat $1 &amp;gt;/tmp/pre_publish_dump.txt

printf '{ "result" : "success"}'
exit 0
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With or without a "\n" at the end of the printf, and when using "echo" instead, the output in SmartConsole is the same after a Publish operation. &amp;nbsp;Seems kinda weird.&lt;/P&gt;
&lt;P&gt;I looked through $MDS_FWDIR/log/cpm.elg as well, and it says the same (no surprise):&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;14/03/25 21:47:36,705  INFO internal.executors.RunScriptActionExecutor [taskExecutor-316]: Script execution finished, exit code: 0, output: 
{ "result" : "success"}, commandError 
14/03/25 21:47:36,705 ERROR coresvc.internal.JobsSvcImpl [taskExecutor-316]: SmartTask execution output contains non-printable characters. Output as bytes: [10, 123, 32, 34, 114, 101, 115, 117, 108, 116, 34, 32, 58, 32, 34, 115, 117, 99, 99, 101, 115, 115, 34, 125]
14/03/25 21:47:36,705  INFO coresvc.internal.JobsSvcImpl [taskExecutor-316]: Action execution of SmartTask [7707d084-ebb9-4596-a421-2b0b41cf7441] succeeded
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just wanna make sure it's not just me going insane... (well, &amp;nbsp;any more than I already am!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Mar 2025 21:53:25 GMT</pubDate>
    <dc:creator>Duane_Toler</dc:creator>
    <dc:date>2025-03-14T21:53:25Z</dc:date>
    <item>
      <title>SmartTask output contains non-printable characters</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243842#M8978</link>
      <description>&lt;P&gt;Sooo... I guess this is normal?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-03-14 at 5.47.44 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/29917i5AF1D33705696033/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-03-14 at 5.47.44 PM.png" alt="Screenshot 2025-03-14 at 5.47.44 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Test script is just a simplistic one to get started:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#!/bin/bash
cat $1 &amp;gt;/tmp/pre_publish_dump.txt

printf '{ "result" : "success"}'
exit 0
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With or without a "\n" at the end of the printf, and when using "echo" instead, the output in SmartConsole is the same after a Publish operation. &amp;nbsp;Seems kinda weird.&lt;/P&gt;
&lt;P&gt;I looked through $MDS_FWDIR/log/cpm.elg as well, and it says the same (no surprise):&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;14/03/25 21:47:36,705  INFO internal.executors.RunScriptActionExecutor [taskExecutor-316]: Script execution finished, exit code: 0, output: 
{ "result" : "success"}, commandError 
14/03/25 21:47:36,705 ERROR coresvc.internal.JobsSvcImpl [taskExecutor-316]: SmartTask execution output contains non-printable characters. Output as bytes: [10, 123, 32, 34, 114, 101, 115, 117, 108, 116, 34, 32, 58, 32, 34, 115, 117, 99, 99, 101, 115, 115, 34, 125]
14/03/25 21:47:36,705  INFO coresvc.internal.JobsSvcImpl [taskExecutor-316]: Action execution of SmartTask [7707d084-ebb9-4596-a421-2b0b41cf7441] succeeded
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just wanna make sure it's not just me going insane... (well, &amp;nbsp;any more than I already am!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 21:53:25 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243842#M8978</guid>
      <dc:creator>Duane_Toler</dc:creator>
      <dc:date>2025-03-14T21:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: SmartTask output contains non-printable characters</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243843#M8979</link>
      <description>&lt;P&gt;Huzzah! &amp;nbsp;I found a bug. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &amp;nbsp;Still doesn't address the original oddity above, tho.&lt;/P&gt;
&lt;P&gt;I'll get this to TAC, but in case anyone else tries this:&lt;/P&gt;
&lt;P&gt;If you load a Bash script containing a line that checks to match a regular expression, the script import strips out the '~' part:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#!/bin/bash

bad_rule_re="[^[:alnum:] _\.-]"

while read rule_name; do
  if [[ $rule_name =~ ${bad_rule_re} ]]; then
    printf '{ "result" : "failure", "message" : "%s" }\n' "Rule '${rule_name}' must not contain special characters (comma, slash, etc.)."
    exit 0
  fi
done &amp;lt;&amp;lt;&amp;lt;$(cat /tmp/pre_publish.txt |jq -r '.operations."modified-objects"[] |select(."new-object".type == "access-rule")."new-object" |.name ')
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "=~" operator on Line 6 gets stripped to just "=". &amp;nbsp;Oops.&lt;/P&gt;
&lt;P&gt;R81.20, MDS, Jumbo HFA 84 (yes, i know, needs to be updated). &amp;nbsp;JHF release notes didn't have anything for SmartTasks past JHF 79 anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 22:34:39 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243843#M8979</guid>
      <dc:creator>Duane_Toler</dc:creator>
      <dc:date>2025-03-14T22:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: SmartTask output contains non-printable characters</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243844#M8980</link>
      <description>&lt;P&gt;An alternative workaround, however, that does work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#!/bin/bash

bad_rule_re="[^[:alnum:] _\.-]"

while read rule_name; do
  if echo "${rule_name}" | grep -E -q "${bad_rule_re}" ; then
    printf '{ "result" : "failure", "message" : "%s" }\n' "Rule '${rule_name}' must not contain special characters (comma, slash, etc.)."
    exit 0
  fi
done &amp;lt;&amp;lt;&amp;lt;$(cat /tmp/pre_publish.txt |jq -r '.operations."modified-objects"[] |select(."new-object".type == "access-rule")."new-object" |.name ')

printf '{ "result" : "success"}\n'

exit 0
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason for this check is so that when someone adds/edits a rule in SmartConsole, I don't have to account for special characters in an Ansible playbook later with YAML and the quoting "gotchas".&lt;/P&gt;
&lt;P&gt;I'll put this in the CheckMates Toolbox as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 22:53:46 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/SmartTask-output-contains-non-printable-characters/m-p/243844#M8980</guid>
      <dc:creator>Duane_Toler</dc:creator>
      <dc:date>2025-03-14T22:53:46Z</dc:date>
    </item>
  </channel>
</rss>

