Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Andy_Bretten
Explorer

Random API Methodology thoughts

Disclaimer:  not a hard core programmer , so I might say crazy things.

I thought I would just share my initial impressions and feedback on a simple proof of concept I've been working on with the new R80 API.

Adding a host.    On the surface this is simple....format a JSON query with a couple of fields and you can add an object to Smartcenter,  awesome.  That works.

Now I've complicated it by purposely sending a duplicate object IP address.   Now I get a HTTP 500 back.

Ok I think,   I need to check for dupe, before adding the object.

Ok I cant search for a match via the API (unless I've missed that),  so I can dump a list of hosts.

Ok that just gives me a list of object names back,  so now I start recursively doing a show host on every host object to suck in all the ip addresses into my perl script to decide if I'm about to dupe.


This feels like alot of work I'm creating,  anyone want to share any thoughts on the API methodology here ?

EDIT: ok so I realized there was a "show more" link in the API docs for "show-hosts" and I can send "details-level":"full" to get the ip addresses of the host objects ... awesome.

2 Replies
Uri_Bialik

I'd suggest the following flow:

1) call add-host (without checking if another object with the same ip-address already exists).

2) If the server responds with an error message, check the message

2.1) If an object with the same name already exist, call "show-host" and provide it with the object name - if it has the correct IP address - you're done. If it has a different IP address, you should probably give your new host a different name.

2.2) If you get a "duplicate ip-address warning", you can search the objects database like this:

POST {{server}}/show-objects

Content-Type: application/json

X-chkp-sid: {{session}}

{

  "in" : [ "text", "192.168.0.1" ],

  "details-level" : "full"

}

or in mgmt_cli syntax:

mgmt_cli show objects in.0 text in.1 192.168.0.1 details-level full

This search should have the same results as searching the objects list in the GUI.

0 Kudos
Uri_Bialik

Typing this (long) line in "expert-mode", shows the names of all the objects that match the search for "192.168.0.1":

[Expert@gw-8b3711:0]# mgmt_cli show objects in.0 text in.1 192.168.0.1  -r true --format json| $CPDIR/jq/jq ".objects[] | .name"

"host1"

[Expert@gw-8b3711:0]#

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events