Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
AntonMakarychev
Contributor
Contributor

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()

 

2019-04-25_16-41-38.png

 

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.

0 Kudos
6 Replies
PhoneBoy
Admin
Admin

I'm not a python programmer, but where are you defining the gateways on which to execute the cpstat fw command?
I don't see you passing it to your run_script function or defined anywhere in the script you pasted above.
0 Kudos
AntonMakarychev
Contributor
Contributor

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’]

 

0 Kudos
PhoneBoy
Admin
Admin

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

0 Kudos
Valeriy_Denisov
Ambassador
Ambassador

gkgkd534
Explorer

Have you succeeded to fix this issue?

I have the same issue too.

0 Kudos
brunomelo
Explorer

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.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events