import requests
import json
import base64
# 1. Login
# 2. Run Script
payload_run_script="{\r\n \"script-name\" : \"Script show SIC Certificate\",\r\n \"script\" : \"cpca_client lscert -kind SIC\",\r\n \"targets\" : [ \"Test-SMC\" ]\r\n}"
headers = {
'Content-Type': 'application/json',
'X-chkp-sid': '{}'.format(sid_value),
'Cookie': 'Session=Login'
}
response_run_script = requests.request("POST", url_run_script, headers=headers, data=payload_run_script, verify=False)
print(response_run_script.text)
task_id_value = (json.loads(response_run_script.text)['tasks'][0]['task-id'])
# 3. Show Task
payload_show_task="{\r\n \"task-id\" : \""+task_id_value+"\",\r\n \"details-level\" : \"full\"\r\n}"
headers = {
'Content-Type': 'application/json',
'X-chkp-sid': '{}'.format(sid_value),
'Cookie': 'Session=Login'
}
response_show_task = requests.request("POST", url_show_task, headers=headers, data=payload_show_task, verify=False)
#Decode base64 from resonpeMessage
response_message = (json.loads(response_show_task.text)['tasks'][0]['task-details'][0]['responseMessage'])
response_mess_file = open("output.json", "w")
response_mess_file.write(response_show_task.text)
response_mess_file.close()
sic_cert_output = base64.b64decode(response_message)
print(sic_cert_output)
#Export SIC Cert output to file
sic_cert_file = open("SIC_cert.txt", "w")
sic_cert_file.write(str(sic_cert_output).replace('\\n', '\n'))
sic_cert_file.close()
When I run this script, the responseMessage field does not return a result. I had to try running the script 10 times to get the result one.
Payload: {
"tasks" : [ {
"uid" : "aa9c4e4a-4cd2-4033-a7e6-166b878827e3",
"name" : "Test-SMC - Script show SIC Certificate",
"type" : "CdmTaskNotification",
"domain" : {
"uid" : "41e821a0-3720-11e3-aa6e-0800200c9fde",
"name" : "SMC User",
"domain-type" : "domain"
},
"task-id" : "88c1a492-155c-4243-9711-224f28f367ed",
"task-name" : "Test-SMC - Script show SIC Certificate",
"status" : "in progress",
"progress-percentage" : 10,
"start-time" : {
"posix" : 1607337340124,
"iso-8601" : "2020-12-07T17:35+0700"
},
"last-update-time" : {
"posix" : 1607337340124,
"iso-8601" : "2020-12-07T17:35+0700"
},
"suppressed" : false,
"task-details" : [ {
"uid" : "4aff5b60-ce30-4ceb-af0a-6584df9fe949",
"name" : null,
"domain" : {
"uid" : "41e821a0-3720-11e3-aa6e-0800200c9fde",
"name" : "SMC User",
"domain-type" : "domain"
},
"color" : "black",
"statusCode" : "in progress",
"statusDescription" : "",
"taskNotification" : "aa9c4e4a-4cd2-4033-a7e6-166b878827e3",
"gatewayId" : "051adfc9-77e4-7143-aacc-e43cbbb2e38c",
"gatewayName" : "",
"transactionId" : 273232546,
"responseMessage" : "",
"responseError" : "",
"meta-info" : {
"validation-state" : "ok",
"last-modify-time" : {
"posix" : 1607337340155,
"iso-8601" : "2020-12-07T17:35+0700"
},
"last-modifier" : "admin",
"creation-time" : {
"posix" : 1607337340155,
"iso-8601" : "2020-12-07T17:35+0700"
},
"creator" : "admin"
},
"tags" : [ ],
"icon" : "General/globalsNa",
"comments" : "",
"display-name" : "",
"customFields" : null
} ],
"comments" : "In Progress...",
"color" : "black",
"icon" : "General/globalsNa",
"tags" : [ ],
"meta-info" : {
"lock" : "unlocked",
"validation-state" : "ok",
"last-modify-time" : {
"posix" : 1607337340148,
"iso-8601" : "2020-12-07T17:35+0700"
},
"last-modifier" : "admin",
"creation-time" : {
"posix" : 1607337340148,
"iso-8601" : "2020-12-07T17:35+0700"
},
"creator" : "admin"
},
"read-only" : false
} ]
}
Please help me. Thanks.
Regards,