cancel
Showing results for 
Search instead for 
Did you mean: 
Create a Post
API / CLI Discussion and Samples

Do you have questions on how to use any of Check Point's API commands, including via the CLI using mgmt_cli? Looking for sample code? This is the place to find answers!

Employee

Create list of IPS protections set for packet capture in a specific profile

Used mgmt_cli to generate a json formatted file (ips.json) of all IPS protections (mgmt_cli show threat-protections details-level full) but cannot figure out how to parse out only the profiles with packet capture enabled. cat ips.json | jq ".protections [] | [.name, .profiles]"

Error when trying to export package by import_export_package.py

Hi allI have a trouble when trying to export a package from SMC. The message like this :Exporting NAT policyGetting information from show-nat-rulebaseRetrieved 50 out of 65 rules (76%)Traceback (most recent call last):File "import_export_package.py", line 59, in <module>export_package(client, args)File "D:\Python\ExportImportPolicyPackage-master\exporting\export_package.py", line 59, in export_packagenat_data_dict, nat_unexportable_objects = export_nat_rulebase(show_package.data["name"], client)File "D:\Python\ExportImportPolicyPackage-master\exporting\export_nat_rulebase.py", line 13, in export_nat_rulebaserulebase_rules, general_objects = get_query_nat_rulebase_data(client, {"package": package})File "D:\Python\ExportImportPolicyPackage-master\exporting\export_objects.py", line 174, in get_query_nat_rulebase_dataif "Automatic Generated Rules : " in rulebase_item["name"]:KeyError: 'name'Does anyone have any ideas for this ?Thank youRegards
Employee

Adding a VLAN to a gateway object using Ansible?

I'm using the new Ansible module to orchestrate my lab, and have noticed a quirk in the documentation. From https://docs.ansible.com/ansible/devel/modules/cp_mgmt_simple_gateway_module.html, there is a note on the interfaces item: "Network interfaces. When a gateway is updated with a new interfaces, the existing interfaces are removed." Has anyone tried adding a VLAN using the official modules? I'm thinking it might just be easier to call a script that connects via ssh and adds it via CLI...

Testing Controls for Bash Scripts

Given the amount of resources a bash script can consume, along with any possible service impact it might have, I have been trying to compile a list of 'testing controls' to benchmark any script against before using it on any Check Point device by carrying out the following steps in a lab environment:1) Observe the resources being consumed by the script. This can be done by having two additional Putty sessions open and run the following commands :- watch free -m- top 2) Ensure that there is no service impact by monitoring critical services such as VPN tunnels etc. 3) Ensure that only a specific group of admins have execution privileges over the script. I would appreciate other people's feedback on this topic, particularly of guys like @Robert_Decker and @Danny who are well versed in the art of scripting. My point is that I am after a process to follow when creating scripts for Check Point devices in order to get the maximum value while causing the least possible amount of disruption. Thanks in advance!   

Having issues with publishing policy via web API

Hi,I have a powershell script that is meant to do the following but is failing on publishing policy.  The API gives me the following error but not sure why as I don't have any unpublished changes.  Below are the steps.-Add Host (Sucess)-Add Host to Group (Sucess)-Publish Policy (Fail)-Install Policy (Fail)2019-11-13 09:43:11,233 INFO [GUI] org.apache.cxf.interceptor.LoggingInInterceptor.log:250 [qtp2049910860-30] - Inbound Message----------------------------ID: 76Address: http://127.0.0.1:50276/web_api/add-hostEncoding: ISO-8859-1Http-Method: POSTContent-Type: application/jsonHeaders: {Accept=[text/plain], connection=[keep-alive], Content-Length=[92], content-type=[application/json], Host=[127.0.0.1:50276], User-Agent=[mgmt_cli_gui], X-chkp-debug=[GUI], X-chkp-sid=[aM8KIGMuWuP8rNWBhDI8LzLVXZtR6-z9kIVee-EFYmc], X-Forwarded-For=[127.0.0.1], X-Forwarded-Host=[127.0.0.1], X-Forwarded-Host-Port=[443], X-Forwarded-Server=[10.130.181.25]}Payload: {"groups":"AttackersList","ip-address":"144.139.158.155","name":"attacker-144.139.158.155"}--------------------------------------2019-11-13 09:43:11,238 INFO [GUI] com.checkpoint.management.web_api_is.utils.helpers.ApiCache.<init>:21 [qtp2049910860-30] - Cache created and initialized2019-11-13 09:43:11,239 INFO [GUI] com.checkpoint.management.web_api.web_services.WebApiEntryPoint.logRequestedCommandInfo:51 [qtp2049910860-30] - Executing [add-host] of version 1.3 (references 1)2019-11-13 09:43:11,834 ERROR [GUI] com.checkpoint.management.web_api.utils.WebApiCommandExceptionUtils.getErrorReply:94 [qtp2049910860-30] -com.checkpoint.web_services.faults.ValidationRemoteFault: 2 Blocking validation errors were found.at sun.reflect.GeneratedConstructorAccessor264.newInstance(Unknown Source)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)at java.lang.reflect.Constructor.newInstance(Constructor.java:437)at org.apache.cxf.interceptor.ClientFaultConverter.processFaultDetail(ClientFaultConverter.java:182)at org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:82)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:802)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1642)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1533)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1336)at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:652)at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)at com.sun.proxy.$Proxy244.updateObjectWithReturnControlErrorLevel(Unknown Source)at com.checkpoint.management.web_api_is.utils.managers.RemoteObjectCrudManager.updateObjectWithReturn_aroundBody30(RemoteObjectCrudManager.java:24)at com.checkpoint.management.web_api_is.utils.managers.RemoteObjectCrudManager$AjcClosure31.run(RemoteObjectCrudManager.java:1)at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)at com.checkpoint.management.web_api_is.aspects.logging.WebApiMethodLoggerAspect.aroundMethodLoggerTest(WebApiMethodLoggerAspect.java:13)at com.checkpoint.management.web_api_is.utils.managers.RemoteObjectCrudManager.updateObjectWithReturn(RemoteObjectCrudManager.java:72)at com.checkpoint.management.web_api_is.core.handler.base.ApiObjectRequestHandler.doUpdateObjectForAdd(ApiObjectRequestHandler.java:34)at com.checkpoint.management.web_api_is.core.handler.base.ApiCrudRequestHandler.add_aroundBody0(ApiCrudRequestHandler.java:19)at com.checkpoint.management.web_api_is.core.handler.base.ApiCrudRequestHandler$AjcClosure1.run(ApiCrudRequestHandler.java:1)at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)at com.checkpoint.management.web_api_is.aspects.logging.WebApiMethodLoggerAspect.aroundMethodLoggerTest(WebApiMethodLoggerAspect.java:13)at com.checkpoint.management.web_api_is.core.handler.base.ApiCrudRequestHandler.add(ApiCrudRequestHandler.java:52)at com.checkpoint.management.web_api.core.handler.objects.network_objects.host.HostRequestHandler.add(HostRequestHandler.java:11)at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)at java.lang.reflect.Method.invoke(Method.java:508)at com.checkpoint.management.web_api_is.utils.WebApiReflectionUtils.invoke(WebApiReflectionUtils.java:7)at com.checkpoint.management.web_api.web_services.WebApiEntryPoint.postEntryPoint(WebApiEntryPoint.java:81)at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)at java.lang.reflect.Method.invoke(Method.java:508)at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181)at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97)at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204)at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101)at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)at org.eclipse.jetty.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:247)at org.eclipse.jetty.servlets.CrossOriginFilter.doFilter(CrossOriginFilter.java:210)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)at com.checkpoint.management.web_api.core.filter.LogCustomDebugFieldFilter.doFilter(LogCustomDebugFieldFilter.java:19)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)at org.eclipse.jetty.server.handler.IPAccessHandler.handle(IPAccessHandler.java:203)at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)at org.eclipse.jetty.server.Server.handle(Server.java:370)at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)at java.lang.Thread.run(Thread.java:785)

How to delete more than 10,000 network objects at a time

Hi GuyesMay I ask a queation?How to delete more than 10,000 network objects at once?I want to delete 'Fortigate Tags' network objects.GAIA : R80.30 or R80.20Thanks 
DemisT
DemisT inside API / CLI Discussion and Samples Wednesday
views 182 2

Ansible 2.9: using the new Check Point modules, getting invalid/incorrect password

Hey,With the new Check Point modules released in Ansible 2.9, I'm trying to run a simple Ansible playbook. Unfortunately when running the playbook, I'm getting an error that says:  fatal: [SMS]: UNREACHABLE! => {"changed": false, "msg": "Invalid/incorrect password: This system is for authorized use only.\nPermission denied, please try again.", "unreachable": true}  I have enabled the API from SmartConsole dashboard under Manage & Settings > Blades > Management API > All IP addresses and performed an API restart.I've also installed the relevant hotfix (Check_Point_R80.30_JHF_T76_Ansible_Hotfix_sk114661_FULL.tgz) and verified with show installer packages installed.The playbook looks like this:  --- - name: test hosts: management connection: httpapi gather_facts: no tasks: - name: show-networks cp_mgmt_network_facts: details_level: standard register: response   My host file looks like this:  [management:vars] ansible_connection=ssh ansible_user=<Smartconsole user> ansible_password=<SmartConsole password> ansible_python_interpreter="/opt/CPsuite-R8*/fw1/Python/bin/python" ansible_httpapi_validate_certs=False ansible_httpapi_use_ssl=True ansible_network_os=checkpoint   I've verified logging into Smart Console manually with these credentials, which is working. Also a curl command from the ansible host seems to be working: curl -vvvv -H "Content-Type: application/json" -X POST -d '{"user":"demis","password":"adminsystempass123"}' <a href="<a href="https://10.23.112.110/web_api/login" target="_blank">https://10.23.112.110/web_api/login</a>" target="_blank"><a href="https://10.23.112.110/web_api/login</a" target="_blank">https://10.23.112.110/web_api/login</a</a>> --insecure  What am I missing? Edit: I was using the SmartConsole username/password which is probably why the error occurred, but changing it to the Gaia OS username/password gives me this error:An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AssertionError: socket_path must be a value fatal: [SMS]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 102, in <module>\n File \"<stdin>\", line 94, in _ansiballz_main\n File \"<stdin>\", line 40, in invoke_module\n File \"/opt/CPsuite-R80.30/fw1/Python/lib/python2.7/runpy.py\", line 192, in run_module\n fname, loader, pkg_name)\n File \"/opt/CPsuite-R80.30/fw1/Python/lib/python2.7/runpy.py\", line 72, in _run_code\n exec code in run_globals\n File \"/tmp/ansible_cp_mgmt_network_facts_payload_FzOYM2/ansible_cp_mgmt_network_facts_payload.zip/ansible/modules/cp_mgmt_network_facts.py\", line 131, in <module>\n File \"/tmp/ansible_cp_mgmt_network_facts_payload_FzOYM2/ansible_cp_mgmt_network_facts_payload.zip/ansible/modules/cp_mgmt_network_facts.py\", line 126, in main\n File \"/tmp/ansible_cp_mgmt_network_facts_payload_FzOYM2/ansible_cp_mgmt_network_facts_payload.zip/ansible_collections/check_point/mgmt/plugins/module_utils/checkpoint.py\", line 170, in api_call_facts\n File \"/tmp/ansible_cp_mgmt_network_facts_payload_FzOYM2/ansible_cp_mgmt_network_facts_payload.zip/ansible/module_utils/connection.py\", line 121, in __init__\nAssertionError: socket_path must be a value\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
Rambod_Fard
Rambod_Fard inside API / CLI Discussion and Samples Wednesday
views 3598 19 3

SmartMove error - converting ASA to CheckPoint

I am trying to convert my ASA config to CheckPoint by SmartMove and receive following error message:"Object reference not set to an instance of an object"Does anyone have any suggestion? Thanks,

API Cluster build

Hello All,Can somebody tell me if there is any possibility how to add a Cluster to the Mgmt (CMA) over the API?I found only the "add-simple-gateway" but nothign else?Thanks for infoRadek

Reading logs in the Management API ?

I see no support for reading logs (audit or rule) in the R80.10 Management API.Am I missing it ?Is it likely to appear in future ?Thanks-gf-
Uri_Bialik
inside API / CLI Discussion and Samples a week ago
views 18563 25 6
Mod

Getting a "Forbidden" error message (HTTP status code 403)

In some scenarios browsing to https://<management-server>/web_api/ may lead to seeing this error message:ForbiddenYou don't have permission to access /web_api/login on this server.What does it mean?It means that the API server is not configured to accept requests from the machine running your browser.For security reasons, the default settings for the API server allows him to accept requests only from the management server itself and not from any other IP address.If you want your management server to accept API requests from other machines, please follow this procedure:* Open SmartConsole and log into your management server. If you have a multi-domain environment, log into the MDS domain.* Click on the "Manage & Settings" button on the left.* Select "Blades"* Look for the "Management API" section and click on "Advanced Settings".Now you can choose between three options:1) Accept API calls from the management server only (the default setting)2) All IP addresses that can be used for GUI clients.    This option would allow the API server to accept requests only from IP addresses that can be used to connect with the management server using SmartConsole.3) All IP addressesOnce you make you selection:* Click the publish button* Use SSH to log into the management server in "expert mode" and type "api restart".
DemisT
DemisT inside API / CLI Discussion and Samples a week ago
views 320 3

GAiA API failing to install with Ansible

Hi all, I have the following task in my ansible playbook for installing the GAiA API (version 1.3) on my gateways and SMS:- name: Install gaia_api  shell: ./install_gaia_api.sh  args:    chdir: /home/admin/gaia_api  register: output- name: Output  debug:    var: output.stdout_lines When I'm running the playbook on my gateways (reimaged with blink_image_1.1_Check_Point_R80.30_Gateway.tgz) and SMS (reimaged with blink_image_1.1_Check_Point_R80.30_Management.tgz), I'm getting the following output after performing a 'gaia_api status' on the gateways, but on the SMS everything seems to be working fine: [Expert@GW1:0]# gaia_api statusTraceback (most recent call last):File "/rest_api/ckp/client_util/serverStatusPrinter.py", line 2, in <module>from objects.serverStatus import *File "/rest_api/ckp/objects/serverStatus.py", line 1, in <module>from infra.annotations import *File "/rest_api/ckp/infra/annotations.py", line 3, in <module>import rest_rbaFile "/rest_api/libs/rest_rba.py", line 7, in <module>import sessions_managerFile "/rest_api/libs/sessions_manager.py", line 12, in <module>import rest_api_xml_parserFile "/rest_api/libs/rest_api_xml_parser.py", line 8, in <module>import command_factory as factFile "/rest_api/libs/command_factory.py", line 10, in <module>import clishFile "/rest_api/libs/clish.py", line 5, in <module>from flaskApi import getRequestHeaderFile "/rest_api/libs/flaskApi.py", line 12, in <module>from flask import *ImportError: No module named flask I've checked the Ansible output and even though it says the installation completed successfully it's still giving me the output errors when running gaia_api status. But when I manually run the install_gaia_api.sh script it seems to be working.ok: [GW1] => {"output.stdout_lines": ["Starting gaia_api installation","Old version removed successfully","Installing gaia_api...","Successfully installed gaia_api, use \"gaia_api status\" to monitor the state"]} I have my Python interpreter set as: ansible_python_interpreter="/opt/CPsuite-R8*/fw1/Python/bin/python"Remarkably, when I use ansible_python_interpreter=python, I'm getting the following error on the gateways (not on the SMS): fatal: [GW2]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.23.112.102 closed.\r\n", "module_stdout": "/bin/sh: python: command not found\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": Which makes me think it's a Python issue.Any suggestions? I'd appreciate some input.
Zeke
Zeke inside API / CLI Discussion and Samples a week ago
views 328 1

Trigger API system backups via API

Hello,I'm an absolute novice to firewalls, but I'm fairly familiar with automation using Ansible, Chef, Puppet, etc and the use of APIs.one of the network engineers presented a use case to trigger "system backups". I'm already able to do configuration backups using Ansible, but the use case presented to me shows "system backups" being triggered from an MDS to multiple gateways. I'm curious about the capabilities of the management API to be able to programmatically trigger these system backups as they seem to contain more than just the "show configuration" command.can anyone point me in the right direction on how to execute this via API call or via a console (CLI/SSH)?Is this feasible/necessary? Regards, Zeke
Greg_Dunlap
Greg_Dunlap inside API / CLI Discussion and Samples a week ago
views 230 1 1

Python API Lib set

a few months ago i found a code snip on here of python calling the web api and i wanted to expand on it to make a more extensible library set.https://github.com/celticcow/r80api-functionshas the library set with a test script ... a LOT of debug info is returned.  I've been able to take this and make web front ends via simple cgi calls to automate a lot of firewall object builds etc ..the idea is to call a function like add_a_host that will take arguments and do the json work for you ... and check things like does a host already exist with this IP.  or add_a_host_with_group which will add a host ... if a host object does NOT exist with this IP already.  if a host with that IP exist it will add that host object to the group name that is passed as an argument.   does similar things with networks and IP ranges. example:""" add a host object and add it to a group """ def add_a_host_with_group(ip_addr, name, ip, group, sid): print("temp -- in add_a_host<br>") check_host_obj = {"type" : "host", "filter" : ip, "ip-only" : "true"} chkhst = api_call(ip_addr, "show-objects", check_host_obj, sid) if(chkhst['total'] == 0): #need new host if(name_exist(ip_addr, name, sid) == False): host_to_add = {"name" : name, "ip-address" : ip, "groups" : group, "color" : "light green"} out1 = api_call(ip_addr, "add-host", host_to_add, sid) print(json.dumps(out1)) else: print("object with that name already exist") else: # host exist ... print("host already exist") existing_host_name = chkhst['objects'][0]['name'] # name of existing host add_host_to_group_json = { "name" : group, "members" : { "add" : existing_host_name } } out1 = api_call(ip_addr, "set-group", add_host_to_group_json, sid) print(json.dumps(out1)) so in the main code you can just do something like:apifunctions.add_a_host_with_group(ip_addr, "test176", "192.168.176.200", "group1", sid) this will attempt to create a host object named "test176" with ip 192.168.176.200 into a group named "group1" unless something already exist with that IP and then it will add that.ip_addr = raw_input("Enter IP of MDS : ") ip_cma = raw_input("Enter IP of CMA : ") user = raw_input("Enter P1 User : ") password = getpass.getpass('Enter P1 Password :') sid = apifunctions.login(user, password, ip_addr, ip_cma) will get you sid for the login. hope this is helpful.  it's been a huge time savor for me when we're building out policies and i can create a web form for engineers to dump data into and it will create / search for them.
Jim_Oqvist
inside API / CLI Discussion and Samples 2 weeks ago
views 18510 22 25
Employee+

How-to use Postman with R80 Security Management API

What is Postman Postman is a free Google Chrome extension that can be used for testing and experimenting with web-services You can find the latest postman collection file for R80 Security Management API here postman_collection.json   Installation 1) Launch "Google Chrome" and enter "chrome://apps" in the URL bar. 2) Open "Web Store" 3) Search for "Postman" 4) Click on "Add to Chrome" and the following should appear: 5) Add the app and then click on "Launch App"   Setup Postman to work with the R80 Security Management API 1) You can import a list of APIs into your Postman environment using Postman's "collection" feature. This stored list of APIs can help you avoid syntax errors and save you time finding APIs. The various Postman collections can be found as follows: API v 1.00 R80 - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80/td-p/38853 API v 1.1 R80.10 - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80-10/td-p/38806 API v 1.2 R80.20.M1 - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80-20-M1/td-p/40310 API v 1.3 R80.20 GA - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80-20/td-p/40569 API v 1.4 R80.20.M2 - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80-20-M2/td-p/40952 API v 1.5 R80.30 - https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/postman-collection-R80-30/m-p/539... 2) Launch Postman, and click on the "import collection" button. 3) Select "choose files" and select the collection file that you have. After selecting the file, you should see something like this:      4) On the left part of the screen, you should now see the text similar to "Web API – take hero3– 991000104". Click on this text, to see the list of API calls grouped by categories. 5) To set-up the environment variable, click on "Manage environments" and click on add     ---->  6) Add a key called "server" and set it with the value: https://<your-mgmt-ip-address>/web_api 7) Add a key called "session", you can leave its value empty. 😎 Click the "Add" button, to exit this dialog. 9) Click the "X" button to exit the “Manage Environments” screen Activating and testing the R80 Security Management API 1) Open SmartConsole R80, and login to the R80 Security Management 2) When the GUI is opened, go to : Manage & settings -> Blades -> Management API -> Advanced Settings 3) Check “Automatic start”, and pick “All IP Addresses that can be used for GUI clients or All IP addresses”. 4) Press OK 5) Publish 6) Run the command api reconf from clish 7) Make sure the management API server is up and running. Browse to: https://<your-mgmt-ip-address>/api_docs/ You need to accept the self signed certificate warning 😎 You should now see the R80 Management API reference guide   9) In Postman: (A) change the postman environment to the one you set in the previous step. (B) locate the "Login" command in the list of APIs on the left and click on it.(C) Change the values for the user-name and password.(D) Click on the "send" button 10) The output of the "Login" command contains a session-ID (sid) value. This value should be used by all other API calls in the same session as a way to prove the authenticity of the user behind the API call. To set the session-ID for subsequent API calls select the sid value, right click and select "Set:" -> "session". 11) You're done! Choose any other API calls from the collection and run it.