- CheckMates
- :
- Products
- :
- Developers
- :
- API / CLI Discussion
- :
- Re: run-script output
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Are you a member of CheckMates?
×- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
run-script output
Hi,
How can we retreive output for run-script API command ?
I can see result on Dashboard but it's possible to have this by API ?
Thanks
- Labels:
-
General
- Tags:
- api
- output
- run-script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've find the solution.
Get task with full details :
{
"task-id" : "29118dcb-d3e2-4096-a8ad-e3e2451db891",
"details-level" : "full"
}
And you have in responseMessage field the output in base64.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Marc,
Yes, it is possible to retrieve output from run-script API command. It's returned being encoded to base64 inside the show-task API command response.
Getting run-script output through HTTP request
- Run run-script command (it's asynchronous) and save the task-id from the response.
- Run show-task command providing task-id that was saved in step 1. You have to run show-task command several times until response will contain status "succeeded". You have to run show-task with details-level set to "full".
- Parse show-task response and extract the base64 encoded result by following path showTaskResult.tasks[0]["task-details"][0].responseMessage
- Decode the base64 encoded result (In Javascript it can be done with atob function).
Getting run-script output through mgmt_cli tool (full example)
mgmt_cli -r true run-script script-name "list root" script "ls -l /" targets.1 "my-management" --format json 2> /dev/null \
| $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' \
| base64 -di
Useful links
https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/run-script
https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/show-task
https://sc1.checkpoint.com/documents/R80/APIs/index.html#mgmt_cli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Robert Decker can you update the above example for R80.10/R80.20.M1?
When I try to run something like:
mgmt_cli -r true show-task task-id 0490542b-e741-40b9-be65-45e1e00c9f79 details-level full --format json | $CPDIR/jq/jq -r '(.tasks[0]["task-details"].responseMessage)' | base64 -di
I get:
jq: error: Cannot index array with string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Dameon,
tasks-details is an objects list so try this command :
mgmt_cli -r true show-task task-id 0490542b-e741-40b9-be65-45e1e00c9f79 details-level full --format json | $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' | base64 -di
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dameon,
You have missed the index notation for the ["task-details"], it should be ["task-details"][0], as it is a collection.
Robert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, yes, I did!
Gotta love JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Gotta love jq being included on the Check Point manager! I did not realize it was in there, I may do more in the shell versus remote through the API because of this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What would be the secret to getting this to work with multiple targets? When I run the command below the output only gives me the output for one firewall no matter how many targets I add.
mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json 2> /dev/null | $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' | base64 -di
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Something like this should work:
mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json 2> /dev/null | $CPDIR/jq/jq -r '(.tasks[]["task-details"][].responseMessage)' | base64 -di
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thx you were right. However it still didn't work for me. I figured out after you fixed my task issue that base64 didn't like the output from multiple firewalls. I had to add a while loop to get the output from both firewalls.
mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json | $CPDIR/jq/jq -r '(.tasks[]["task-details"][].responseMessage)' | while read line; do base64 -di <<< "$line"; done
