Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Satya2021
Contributor
Jump to solution

I do have Management Server on Open Server with 4 policy package

I do have four Management Server on Open Server with 4 policy package and want to export all policy package from this Management and import on one Single Management and also doing this sk120342 and after this python toll this givening error.

[Expert@NTPC-MGMT:0]# python import_export_package.py

Welcome to the Policy Package Import/Export Tool.
What would you like to do?
1. Import a package
2. Export a package
99. Exit
2
Please enter a Policy Package name to export:
NTPC_App
Traceback (most recent call last):
File "import_export_package.py", line 26, in <module>
args = process_arguments(arg_parser)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/utils.py", line 96, in process_arguments
args = Menu(args).self_args
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 21, in __init__
self.build()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 146, in build
self.display()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 30, in display
self.handle_input()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 269, in handle_input
self.build()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 146, in build
self.display()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 30, in display
self.handle_input()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 167, in handle_input
self.self_args.name = input()
File "<string>", line 1, in <module>
NameError: name 'NTPC_App' is not defined

0 Kudos
2 Solutions

Accepted Solutions
796570686578
Collaborator

Also, let me know if the steps I showed below worked.

In case it does, in the next step, the username also needs to be entered between to '. So for example 'admin' 

The password doesn't need the two ' 

In case you run into an error that looks like this "TypeError: 'newline' is an invalid keyword argument for this function", let me know, I found a fix for it. 

Was able to export and import the package

 

 

View solution in original post

(1)
796570686578
Collaborator

Ohh alright that error. I had the same error before. What you need to to is, Download the  Check Point API Python SDK  .
Download the Code to your Management(unzipped), and then you need to add the Path to your environmental variable.
Configure your environment variables:

export PYTHONPATH=$PYTHONPATH:<“CP-SDK” FULL PATH>
For example, if you copied the SDK to the path “/home/admin/” the command will be:

export PYTHONPATH=$PYTHONPATH:/home/admin/cp_mgmt_api_python_sdk/

 

for me it was the following: 

export PYTHONPATH=$PYTHONPATH:/home/admin/cp_mgmt_api_python_sdk-master/

after performing these steps you should not get the error anymore!

Edit: Link to python sdk:

https://github.com/CheckPointSW/cp_mgmt_api_python_sdk

View solution in original post

18 Replies
MLad
Explorer

It looks like the policy "NTPC_App" does not exist.

1. Run the "GuiDBedit.exe" Database Tool. Go to "Policies" table -> policies_collections
2. Compare object names with the one used in the script.

 

Best,

Marek

0 Kudos
G_W_Albrecht
Legend Legend
Legend

Looks like package name is incorrect - what are the names of the policy packages ?

CCSP - CCSE / CCTE / CTPS / CCME / CCSM Elite / SMB Specialist
0 Kudos
Satya2021
Contributor

There are two policy package on Management- "Standard" and  "NTPC_App"

 

and I have tried with both but getting same error

0 Kudos
Srdjan_B
Collaborator
Collaborator

GUI names don't necessarily match API names. Try this from expert mode of management server, it will give you the list of packages as seen by API.  If using MDM, you may need additional parameter domain "domain-name-here"

mgmt_cli -r true show packages limit 50 offset 0 details-level "standard" --format json

 

 

0 Kudos
Satya2021
Contributor

Please see the policy packages

 

[Expert@NTPC-MGMT:0]# mgmt_cli -r true show packages limit 50 offset 0 details-level "Standard" --format json
{
"packages" : [ {
"uid" : "e9dc460a-48a8-47e7-89a6-6bb2f5ab1056",
"name" : "NTPC_App",
"type" : "package",
"domain" : {
"uid" : "41e821a0-3720-11e3-aa6e-0800200c9fde",
"name" : "SMC User",
"domain-type" : "domain"
}
}, {
"uid" : "512b2821-ee6d-41d1-a7cb-5ed957d90017",
"name" : "Standard",
"type" : "package",
"domain" : {
"uid" : "41e821a0-3720-11e3-aa6e-0800200c9fde",
"name" : "SMC User",
"domain-type" : "domain"
}
} ],
"from" : 1,
"to" : 2,
"total" : 2
}
[Expert@NTPC-MGMT:0]#

0 Kudos
796570686578
Collaborator

Hi, I just tested the tool and you need to type

'PackageName' so 'NTPC_App'

hope this helps!

0 Kudos
Satya2021
Contributor

Thanks for this.

But I have tested that time with policy packages and it gets same error.

 

Can you please share me Steps for exporting policy and importing

0 Kudos
796570686578
Collaborator

Hmmm did you type in 'NTPC_App' when it asks for the Policy Package Name, so between the two ' ?

I just created a policy Package and named it NTPC_App and didn't have any issues:

[Expert@xxxxxxxxx:0]# python import_export_package.py       

Welcome to the Policy Package Import/Export Tool.
What would you like to do?
1. Import a package
2. Export a package
99. Exit
2
Please enter a Policy Package name to export:
'NTPC_App'
Please select a login method:
1. Enter user credentials manually
2. Login as Root
3. Use an existing session file
4. Use an existing session UID

 

Because that should work from what I see.

Maybe try to rename the Policy, Install Database and try again.

0 Kudos
Satya2021
Contributor

Here is my Steps and still getting error

1- I have downloaded tools from https://github.com/CheckPointSW/ExportImportPolicyPackage and tools name is ExportImportPolicyPackage

2- I have uploaded this tool after unzip on $FWDIR/Python/bin/

3-[Expert@NTPC-MGMT:0]# cd /opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/

4- [Expert@NTPC-MGMT:0]# python import_export_package.py
Traceback (most recent call last):
File "import_export_package.py", line 5, in <module>
from cpapi import APIClient, APIClientArgs
ImportError: No module named cpapi
[Expert@NTPC-MGMT:0]#
 

0 Kudos
796570686578
Collaborator

Ohh alright that error. I had the same error before. What you need to to is, Download the  Check Point API Python SDK  .
Download the Code to your Management(unzipped), and then you need to add the Path to your environmental variable.
Configure your environment variables:

export PYTHONPATH=$PYTHONPATH:<“CP-SDK” FULL PATH>
For example, if you copied the SDK to the path “/home/admin/” the command will be:

export PYTHONPATH=$PYTHONPATH:/home/admin/cp_mgmt_api_python_sdk/

 

for me it was the following: 

export PYTHONPATH=$PYTHONPATH:/home/admin/cp_mgmt_api_python_sdk-master/

after performing these steps you should not get the error anymore!

Edit: Link to python sdk:

https://github.com/CheckPointSW/cp_mgmt_api_python_sdk

Satya2021
Contributor

Thanks. but getting same error

 

[Expert@NTPC-MGMT:0]# python import_export_package.py

Welcome to the Policy Package Import/Export Tool.
What would you like to do?
1. Import a package
2. Export a package
99. Exit
2
Please enter a Policy Package name to export:
NTPC_App
Traceback (most recent call last):
File "import_export_package.py", line 26, in <module>
args = process_arguments(arg_parser)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/utils.py", line 96, in process_arguments
args = Menu(args).self_args
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 21, in __init__
self.build()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 146, in build
self.display()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 30, in display
self.handle_input()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 269, in handle_input
self.build()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 146, in build
self.display()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 30, in display
self.handle_input()
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/menu.py", line 167, in handle_input
self.self_args.name = input()
File "<string>", line 1, in <module>
NameError: name 'NTPC_App' is not defined
[Expert@NTPC-MGMT:0]#

0 Kudos
796570686578
Collaborator

You need to type 'NTPC_App' not NTPC_App

(1)
Satya2021
Contributor

After giving password and it shows error. please help

The script will run with the following parameters:
Export Access-Control layers = True
Export NAT layers = True
Export Threat-Prevention layers = True
Export HTTPS Inspection layers = True
Output-file name = None
Management Server IP = 127.0.0.1
Management Server Port = 443
Management Server Domain = None
1. Change Settings
2. Run
99. Back
'admin'
Invalid input. Please choose an option in the range 1:2 or 99.
2
Please enter your username:
'admin'

Please enter your password:


Traceback (most recent call last):
File "import_export_package.py", line 26, in <module>
args = process_arguments(arg_parser)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/utils.py", line 106, in process_arguments
log_file = open(args.log_file, "w",newline='')
TypeError: 'newline' is an invalid keyword argument for this function
[Expert@NTPC-MGMT:0]#

0 Kudos
796570686578
Collaborator

I had the same error "TypeError: 'newline' is an invalid keyword argument for this function"

The error is because 'newline' was added in python 3 and python 2 doesn't support it yet. So you need to manually edit ALL  'open' functions in utils.py that have "w",newline='' to "w"

so for example

open(args.log_file, "w",newline='') 

change to

open(args.log_file, "w") 

Not 100% sure if you need the "wb" or can leave it as "w" though. I tried with 'w' and it worked fine.

 

 

Satya2021
Contributor

please check this

Please enter your username:
'admin'

Please enter your password:

You currently do not have a record of this server's fingerprint.
Server's fingerprint: EF42F53F988948B14B51374527D066B2C4ED98B6
Do you accept this fingerprint? [y/n] y
Fingerprint saved.
Exporting Access Control layers

Exporting Access Layer [NTPC_App Network]

Retrieved 4 out of 4 rules (100%)

Processing rules and sections

Exporting hosts from layer [NTPC_App Network]

Exporting access rules from layer [NTPC_App Network]

Exporting access sections from layer [NTPC_App Network]

Exporting placeholders for unexportable objects from layer [NTPC_App Network]

Exporting layer settings of layer [NTPC_App Network]

Done exporting layer 'NTPC_App Network'.


Traceback (most recent call last):
File "import_export_package.py", line 61, in <module>
export_package(client, args)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/exporting/export_package.py", line 55, in export_package
timestamp, ["access-rule", "access-section"], client.api_version)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/utils.py", line 228, in create_tar_file
export_to_tar(data_dict, timestamp, tar, lst, api_version)
File "/opt/CPsuite-R80.40/fw1/Python/bin/ExportImportPolicyPackage-master/utils.py", line 244, in export_to_tar
with open(file_name_csv, "w", newline='') as tar_file_csv, open(file_name_json, "w", newline='') as tar_file_json:
TypeError: 'newline' is an invalid keyword argument for this function

0 Kudos
796570686578
Collaborator

Good Morning!

You are still getting the error message "'newline' is an invalid keyword ", so you haven't removed all "newline=''" parameters.

Check the utils.py file again and search for newline. Any function that has the newline parameter, needs to be edited to open(xxxxxx, "w") .

So there is at least one more  in line 244, open(file_name_json, "w", newline=''), change to  open(file_name_json, "w"). Just check the whole file for any newline parameters and remove them

Glad I am able to help.

796570686578
Collaborator

Also, let me know if the steps I showed below worked.

In case it does, in the next step, the username also needs to be entered between to '. So for example 'admin' 

The password doesn't need the two ' 

In case you run into an error that looks like this "TypeError: 'newline' is an invalid keyword argument for this function", let me know, I found a fix for it. 

Was able to export and import the package

 

 

(1)
Satya2021
Contributor

Thank for helping me to exporting policy package

 

Thank you very much

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events