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

Host object re-naming using mgmt_cli (bulk operation)

Host object re-naming using mgmt_cli


Hi all,

I have the requirement to re-name 35000 hosts on my Network.
There is no requirement to change any ip addressing.
The requirement is to re-name the Network host or the Network group.

For example The need to change the following :

original host SEJ-10.10.10.10

New host name : CEJ-SEJ-10.10.10.10

What the requirement is to preceed the original name with a string.

Looking at the what is currently published I see the current thread


https://community.checkpoint.com/t5/Management/Bulk-rename-of-host-objects/td-p/36578

So far I have not managed to get this working correctly.

Can you please advise on the correct process and the correct strings to be used for the execution.

The intention is to initially create a new CSV file and copy to the SMS and then do the function/ manipulate from that CSV import.

Can anyone please advice on correct procedure / process?

 

 

Many thanks,

JED

0 Kudos
5 Replies
AkosBakos
Advisor
Advisor

Hi @JED 

First, try it with small pieces, for eg. one host. 🙂

Add host:

[Expert@mgmt-sakos-lab:0]# mgmt_cli -r true add host name "New Host 2" ip-address "192.0.2.2"

Publish:

[Expert@mgmt-sakos-lab:0]# mgmt_cli -r true publish

Rename host:

[Expert@mgmt-sakos-lab:0]# mgmt_cli -r true set host name "New Host 2" new-name "New Host Akos2"

Publish:

[Expert@mgmt-sakos-lab:0]# mgmt_cli -r true publish

Detalied description here: https://sc1.checkpoint.com/documents/latest/APIs/?#cli/set-host~v2%20

If you don't want to create files to bulk mode with different syntax, you can use concat funciton in Excel to create the script:

[Expert@mgmt-sakos-lab:0]# cat rename.sh
mgmt_cli -r true set host name "New Host 2" new-name "New Host Akos2"
mgmt_cli -r true publish
[Expert@mgmt-sakos-lab:0]# bash rename.sh    

And a tipp: always  publish after every 100 changes!

I hope it make sense.

Akos

----------------
\m/_(>_<)_\m/
0 Kudos
JozkoMrkvicka
Authority
Authority

If you use "-r true", you dont need to call publish operation. It will be done automatically, including logout. Each command using -r true will open new, separated session. Better would be to use session ID.

Kind regards,
Jozko Mrkvicka
AkosBakos
Advisor
Advisor

Thanks for the addition, yes, it makes the publish.

A

----------------
\m/_(>_<)_\m/
0 Kudos
Amir_Senn
Employee
Employee

Publishing like this will cause 35000 publish operation and not recommended at all like @JozkoMrkvicka said.

I think best way is to loop some requests to get the names/uid of all hosts. This also needs to be looped since we can only get up to 500 results per request.

Solution A: login, "show hosts" with limit 1, parse the name and do "set host" with the name and new prefix. Next you run the show hosts with offset increased by 1 and repeat until number of hosts is met. Publish in the end.

Solution B: for less calls, you can get all the uid/names to the same file and loot it until the end.

mgmt_cli show hosts details-level uid limit 500 >> hosts.txt

This brings maximum results of 500 for one time, you need to loop this until 35000 with offset flag.

Kind regards, Amir Senn
JozkoMrkvicka
Authority
Authority

Not sure if UID of host will be helpful here, since the name of the host is needed to be renamed. I will just check with one API call how many host objects are created on management/domain (show hosts limit 1 | jq -r '.total' ). Then I will loop "show hosts" with limit of 100 and offset as variable until the end. Output will be saved locally in text file. Then simple go over each host object, check what is the current name and rename it by adding prefix at the start of the name. Dont forget to publish session after no more than 100 changes for better performance.

Kind regards,
Jozko Mrkvicka

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events