- CheckMates
- :
- Products
- :
- Developers
- :
- API / CLI Discussion
- :
- WebAPI one time script stucks at 10%
- 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
WebAPI one time script stucks at 10%
Hello. I wrote python script to get result of cpstat fw command:
def api_call(ip_addr, port, command, json_payload, sid):
url = 'https://' + ip_addr + ':' + str(port) + '/web_api/' + command
if sid == '':
request_headers = {'Content-Type' : 'application/json'}
else:
request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
r = requests.post(url,data=json.dumps(json_payload), headers=request_headers, verify=False)
return r.json()
def login(user,password):
payload = {'user':user, 'password' : password}
response = api_call(mgmt_server, 443, 'login',payload, '')
return response["sid"]
def run_script(script_name, script_command,sid):
payload = {'script-name':script_name, 'script':script_command, 'targets':otr_gws}
response = api_call(mgmt_server, 443, 'run-script', payload, sid)
return response
def show_task(task_id, sid):
payload = {'task-id':task_id, 'details-level':'full'}
response = api_call(mgmt_server, 443, 'show-task', payload, sid)
return response
def main():
sid = login(mgmt_username,mgmt_password)
print("session id: " + sid)
cpstat = run_script("cpstat","cpstat fw",sid)
print(cpstat)
print("------------------------------")
print("cpstat result: " + json.dumps(cpstat))
print("------------------------------")
task_id=cpstat["tasks"][0]["task-id"]
result=show_task(task_id, sid)
print(result)
logout_result = api_call(mgmt_server, 443,"logout", {},sid)
print("logout result: " + json.dumps(logout_result))
if __name__ == '__main__':
main()
But when I run script it just stucks on the management server and nothing hashappened. What could be the problem?
P.S. The main idea is I want to make script to check ISP Redundancy status and to switch ISP Manually.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see you passing it to your run_script function or defined anywhere in the script you pasted above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The first part of script is:
import requests
import json
mgmt_username = ‘user’
mgmt_password = ‘pass’
mgmt_server = ‘x.x.x.x’
otr_gws = [‘gw-2’]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don’t see you doing a base64 decoding of the command output either.
See: https://community.checkpoint.com/t5/Developers-API-CLI/run-script-output/m-p/2835#M213
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
Here is the solution - https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solut...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you succeeded to fix this issue?
I have the same issue too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had the same problem when i did it in PHP. But i did some tests and i found what it is and how to bypass the problem.
That's a bug in WEBAPI. I'm using R81, so i don't know about other versions.
When you use teh "run-script", the issue will occur if you use a LIST on the "target" parameter. So, if there's more than 1 gateway on target, the tasks will stuck.
Instead a LIST on "target" parameter, try to use a Loop passing one gateway at time.
