cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

58
Views
1
Helpful
6
Replies
Beginner

json-rpc: easy-to-parse show_config response?

json-rpc "show_config" command ("path": "/devices/device/{csr1}/config/ios:interface/GigabitEthernet/{2}") gives out the following response. at least for me it's hard to parse. so my questions are:

1) is there an easy way to parse it?

2) is there a way to get a relatively easy-to-parse response through json-rpc?

thanks

{ "jsonrpc": "2.0",

  "result": {

    "config": "devices {\n    device csr1 {\n        config {\n            ios:interface {\n                GigabitEthernet 2 {\n                    negotiation {\n                        auto true;\n                    }\n                    ip {\n                        address {\n                            primary {\n                                address 192.168.10.2;\n                                mask    255.255.255.0;\n                            }\n                        }\n                    }\n                    load-interval 30;\n                    service-policy {\n                        input  pm-GigabitEthernet2-in;\n                        output audi101-pm_ds-parent;\n                    }\n                }\n            }\n        }\n    }\n}\n"

  },

  "id": 1

}

1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: json-rpc: easy-to-parse show_config response?

Can't tell why you get that results without seeing the complete params you send: check your "result_as" setting.

The following 'query'

{"jsonrpc":"2.0","id":4,"method":"query","params":{"th":1,"context_node":"/ncs:devices/device{'CE11'}/config/ios:interface","xpath_expr":"GigabitEthernet","selection":["name","description","speed","ip/address/primary/ios:address","ip/address/primary/ios:mask"],"chunk_size":25,"initial_offset":1,"result_as":"string"}}

gives me back this result: {"current_position":1,"total_number_of_results":1,"number_of_results":1,"number_of_elements_per_result":5,"results":[["0/1","descrip","100","1.2.3.4","255.255.0.0"]]}

which is comma separated easy to parse.

View solution in original post

6 REPLIES 6
Cisco Employee

Re: json-rpc: easy-to-parse show_config response?

I would not parse such config string, instead, use get_value for each desired parameter.

Beginner

Re: json-rpc: easy-to-parse show_config response?

Xiaorong,

     that's a good tip, but i do prefer minimizing the interaction between my application and nso. is it doable?

     thanks.

Cisco Employee

Re: json-rpc: easy-to-parse show_config response?

Yes, you can use  query (or start_query/run_query/stop_query) to control the number of interactions.

Beginner

Re: json-rpc: easy-to-parse show_config response?

Richard,

     this is what i get out of 'query', again, how to parse it?

     ("xpath_expr": "/devices/device[name='csr1']/config/interface/GigabitEthernet[name='1']")

{

  "jsonrpc": "2.0",

  "result": {

    "number_of_elements_per_result": 1,

    "current_position": 1,

    "results": [

      [

        "1normaltruetruetruetruetruetruetrue1500level-1-2172.32.1.22255.255.255.0truetruetruetruefalsefalsefalsetrue60truetrue30truepm-GigabitEthernet1-incisco_systems-pm_ds-parenttruetruetruetrue"

      ]

    ],

    "total_number_of_results": 1,

    "number_of_results": 1

  },

  "id": 1

}

Cisco Employee

Re: json-rpc: easy-to-parse show_config response?

Can't tell why you get that results without seeing the complete params you send: check your "result_as" setting.

The following 'query'

{"jsonrpc":"2.0","id":4,"method":"query","params":{"th":1,"context_node":"/ncs:devices/device{'CE11'}/config/ios:interface","xpath_expr":"GigabitEthernet","selection":["name","description","speed","ip/address/primary/ios:address","ip/address/primary/ios:mask"],"chunk_size":25,"initial_offset":1,"result_as":"string"}}

gives me back this result: {"current_position":1,"total_number_of_results":1,"number_of_results":1,"number_of_elements_per_result":5,"results":[["0/1","descrip","100","1.2.3.4","255.255.0.0"]]}

which is comma separated easy to parse.

View solution in original post

Highlighted
Beginner

Re: json-rpc: easy-to-parse show_config response?

it looks i have to specify the 'selection' explicitly. my old query didn't contain that param -- actually that's what i want: everything beneath certain node/xpath. anyway if there's no other way, i could write the lengthy 'selection'.

thanks Richard, let me mark it answered.

Content for Community-Ad
FusionCharts will render here