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

HowTo bash get specific value returned only

Hello,

How can I get a specific value returned only using API commands in a bash script ?

E.g. I need a rule name and the rule type reurned only.

Assuming the API was developped using object oriented programming, it should be possible to get a specific value returned only instead all the information related to the rule like listed below.

like

access-rule.name

or

access-rule.type

From the API command listed below I'd like to see following only:

access-rule.name = "Stealth Rule"

or

rulebase.type = "access-rule"

or

access-rule.comments = "MY COMMENT"

=========================================================================================

[Expert@MDS2-R80.10:0]# mgmt_cli show access-rule --domain 'Domain1' layer 'Policy1 Network' uid '1ba15eb2-9fef-4042-9a6e-3842b8a9a231'


Username: script
Password:


uid: "1ba15eb2-9fef-4042-9a6e-3842b8a9a231"
name: "Stealth Rule"
type: "access-rule"
domain:
  uid: "ad3744cb-55c1-4467-8119-1359dd7ca5f4"
  name: "Domain1"
  domain-type: "domain"
track:
  type:
    uid: "598ead32-aa42-4615-90ed-f51a5928d41d"
    name: "Log"
    type: "Track"
    domain:
      uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
      name: "Check Point Data"
      domain-type: "data domain"
  per-session: false
  per-connection: true
  accounting: false
  alert: "none"
layer: "e1c4e6af-1788-4f05-a598-6a995b841948"
source:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
source-negate: false
destination:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
destination-negate: false
service:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
service-negate: false
vpn:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
action:
  uid: "6c488338-8eec-4103-ad21-cd461ac2c473"
  name: "Drop"
  type: "RulebaseAction"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
action-settings: {}
content:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
content-negate: false
content-direction: "any"
time:
- uid: "97aeb369-9aea-11d5-bd16-0090272ccb30"
  name: "Any"
  type: "CpmiAnyObject"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"
custom-fields:
  field-1: ""
  field-2: ""
  field-3: ""
meta-info:
  lock: "unlocked"
  validation-state: "ok"
  last-modify-time:
    posix: 1542012857319
    iso-8601: "2018-11-12T09:54+0100"
  last-modifier: "script"
  creation-time:
    posix: 1542012857319
    iso-8601: "2018-11-12T09:54+0100"
  creator: "script"
comments: "MY COMMENT"
enabled: false
install-on:
- uid: "6c488338-8eec-4103-ad21-cd461ac2c476"
  name: "Policy Targets"
  type: "Global"
  domain:
    uid: "a0bbbc99-adef-4ef8-bb6d-defdefdefdef"
    name: "Check Point Data"
    domain-type: "data domain"

...

.....

Thank you for the help .

Labels (1)
0 Kudos
7 Replies
Highlighted
Sapphire

This is more of a RFE 

0 Kudos
Highlighted

Hello Günther,

so you are saying this is not object oriented programmed ?

0 Kudos
Highlighted
Employee+
Employee+

The language the API is programmed in is irrelevant. What he is saying is, it's not feature we currently provide, therefor a request for enhancement would need to be submitted.

0 Kudos
Highlighted

Bash is not object oriented so can't. You can use usual bash tools like grep, sed, awk to process API output, but your variables won't be object oriented type of course.

0 Kudos
Highlighted
Employee+
Employee+

You can call for json format and use JQ to parse the returned data.

Highlighted
Silver

Hi,

have a look at the SDK GitHub - CheckPointSW/cp_mgmt_api_python_sdk: Check Point API Python Development Kit   and the examples included. with parsing the output as "data", you can just say "give me the value of "rulename""

i.e.(what i did)

if monitor_ips_version.success:
ips_info=monitor_ips_version.data
ips_current_ver_info=ips_info["installed-version"]

ips_update_ver_info=ips_info["latest-version"]

i am aware, you asked for bash and i answered with python, but maybe it helps

Highlighted

Hello David.

yes, it is.

Than you

0 Kudos