cancel
Showing results for 
Search instead for 
Did you mean: 
Create a Post
Highlighted
Silver

rename_objects.sh: bash script using CSV to bulk rename objects (on MDS)

 

Hi,

I've created a bash script to bulk rename objects listed in a CSV file. You need to run it on a MDS with the Management API enabled.

Features

  • Auto-detect API version of MDS.
  • Use CSV file for defining all objects to rename.
  • Bulk rename of TCP service objects is supported.
  • Bulk rename of UDP service objects is supported.
  • Bulk rename of Hosts objects is supported.
  • Bulk rename of Networks is supported.
  • Bulk rename of Service Groups is supported.
  • Bulk rename of Network Groups is supported.
  • Auto publish or no publish after successfully renaming the objects.
  • Auto discard complete session when return value of API call to rename object is not 0 (0=SUCCESS).
  • Display errors/warnings when session is discarded.

 

CSV file

Create a seperate CSV file for each object type you want to rename. This means you cannot mix object types like TCP and UDP services into one CSV file. When running the script you have to specify which object type the CSV file contains.

Each CSV file has to start with a special line:

name,new-name

From that point you can add new lines with current name<comma>new name


Example CSV file with host objects:

name,new-name
Gooogle-DNS1,Google-DNS1
Googgle-DNS2,Google-DNS2

 

Script example

./rename_objects.sh johndoe DMS-CP-1 CHG4726 hosts rename_hosts.csv nopublish

This allows user johndoe to login to the domain DMS-CP-1. It will use changenumber CHG4726 for session name and description. Furthermore you tell that it will find host objects in the CSV file rename_hosts.csv. Last but not least the nopublish action will force a logout of the API session after succesfully renaming the objects. This will allow you to takeover the session in SmartConsole for manual verification and a manual publish if you're satisfied with the results.

 

Usage

Usage:
  ./rename_objects.sh [ARGUMENTS]...

Rename objects listed in a CSV file using the Management API of a Check Point
Multi-Domain Management Server running on R80.x

Mandatory arguments to supply when running the script.
  username       Put your username that has Write access to the DMS here.
  domainname     Put the name of the DMS here.
  changenumber   Put in your changenumber. It will be used for session info.
  objecttype     Can be either tcp|udp|hosts|networks|servicegroups|networkgroups.
  filename       The CSV file that lists the current and new names of the
                 objects.
  sessionaction  Can be either nopublish|publish.

Example:
  ./rename_objects.sh johndoe DMS-CP-1 CHG4726 hosts rename_hosts.csv nopublish

If there are errors or warnings when renaming objects the complete session will
be discarded. A log will be shown so you can fix it before trying again.

The CSV file should always start with this line:
name,new-name

From this point you can add new lines with the current name and the new name of
the objects:
Gooogle-DNS1,Google-DNS1
Googgle-DNS2,Google-DNS2
etc...

When you choose not to publish you can takeover the session in SmartConsole.
In SmartConsole you can then verify the changes and publish it manually.

 

You can download rename_objects.sh on your MDS using the following CLI one-liner:

curl_cli -o rename_objects.sh tools.checkpoint.engineer/rename_objects.sh && chmod +x rename_objects.sh

or in a browser:

https://tools.checkpoint.engineer/rename_objects.sh

 

Changelog

0.1 Initial version

My blog: https://checkpoint.engineer
0 Kudos