cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1043
Views
10
Helpful
8
Replies

NSO - How to get operational data list using json-rpc?

ygorelik
Cisco Employee
Cisco Employee

I have operational data collected in the CDB in a list. When trying to get content of the list using json-rpc I am getting empty result although the list contains multiple entries and I can retrieve it over restconf protocol. I tried various methods like show_config, get_value. Here is the failing query:

$ curl -b cookie -X POST http://localhost:8080/jsonrpc -H 'Content-Type: application/json' -d '
{"jsonrpc":"2.0","id":1,
"method":"show_config",
"params":{
   "th":1,
   "path":"/config-monitor:config-monitor/report-files"
}
}'
{"jsonrpc":"2.0","result":{"config":"config-monitor {\n}\n"},"id":1}

I can get though list keys, which shows that the list is not empty:

$ curl -b cookie -X POST http://localhost:8080/jsonrpc -H 'Content-Type: application/json' -d '
{"jsonrpc":"2.0","id":1,
"method":"get_list_keys",
"params":{
   "th":1,
   "path":"/config-monitor:config-monitor/report-files"
}
}'
{"jsonrpc":"2.0","result":{"keys":[["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.info.txt"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.cfg"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.csv"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.html"]],"total_count":4,"lh":-1},"id":1}

 

1 Accepted Solution

Accepted Solutions

Actually show_config should work. I deployed data according to this module:

module: cfg-mon2
  +--rw cfg-mon2
     +--rw report-files* [path]
        +--rw path    string
        +--rw size?   uint16

The show_config call is working as expected:

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "show_config",
    "params": {
        "th": 1,
        "path": "/cfg-mon2:cfg-mon2/report-files",
        "result_as": "json"
    }
}
{
    "jsonrpc": "2.0",
    "result": {
        "data": {
            "cfg-mon2:cfg-mon2": {
                "report-files": [
                    {
                        "path": "/home/foo",
                        "size": 1984
                    },
                    {
                        "path": "/home/test",
                        "size": 22
                    }
                ]
            }
        }
    },
    "id": 1
}

View solution in original post

8 Replies 8

Marcel Zehnder
Spotlight
Spotlight

Hi 

Does the query method work?

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "query",
    "params": {
        "th": 1,
        "xpath_expr": "/config-monitor:config-monitor/report-files"
    }
}

It almost does:

$ curl -b cookie -X POST http://localhost:8080/jsonrpc -H 'Content-Type: application/json' -d '
{"jsonrpc":"2.0","id":1,
"method":"query",
"params":{
   "th":1,
   "xpath_expr":"/config-monitor:config-monitor/report-files"                              
}
}'

{"jsonrpc":"2.0","result":{"current_position":1,"total_number_of_results":4,"number_of_results":4,"number_of_elements_per_result":1,"results":[["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.info.txt892023-01-13T10:29:18-00:00"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.cfg4492023-01-13T10:29:50-00:00"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.csv18522023-01-13T10:29:18-00:00"],["/Users/ygorelik/test-sync-monitor/config-inspection-reports/ios.nref.html25112023-01-13T10:29:52-00:00"]]},"id":1}

Note, that leaf values (file path, size, creation time) are not separated. Very strange output! So further processing needed to split received values. Any idea, how to get separated leaf values; JSON format is preferred.

Actually show_config should work. I deployed data according to this module:

module: cfg-mon2
  +--rw cfg-mon2
     +--rw report-files* [path]
        +--rw path    string
        +--rw size?   uint16

The show_config call is working as expected:

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "show_config",
    "params": {
        "th": 1,
        "path": "/cfg-mon2:cfg-mon2/report-files",
        "result_as": "json"
    }
}
{
    "jsonrpc": "2.0",
    "result": {
        "data": {
            "cfg-mon2:cfg-mon2": {
                "report-files": [
                    {
                        "path": "/home/foo",
                        "size": 1984
                    },
                    {
                        "path": "/home/test",
                        "size": 22
                    }
                ]
            }
        }
    },
    "id": 1
}

It works, because the yang defines the list as config data. I guess I should do the same.

Thank you for the tips.

Hi Marcel

Could you please try to add 'config false' for the list in the YANG model and repeat the test. The reason is that it would not be a clean solution to have operational data in configuration. We don't want the user change that data from the config!

Thank you for the efforts and suggestions.

Yes, you're correct, if I test this with operational data I get the same empty result as in your first post. I think, in this case the subscribe_cdboper mehod must be used (just a guess, I really don't know the JSON-RPC API well)...

However, why don't you just switch to RESTCONF?

 

I need to do an extension for the web UI, which is all based on JavaScript + HTML. I have some examples on how JavaScript code extracts data from CDB using JSON-RPC, but I do not have any examples how to do that with the Restconf. Plus, the Web UI uses login credentials ones, and then propagates them to all the GUI components. Will that work with Restconf? I have no idea. Need expert opinion.

At this point I can see that method 'query' allows to extract slice of the leafs from the list. That gives at least some working mechanism to retrieve the data. Example:

$ curl -b cookie -X POST http://localhost:8080/jsonrpc -H 'Content-Type: application/json' -d '
{"jsonrpc":"2.0","id":1,
"method":"query",
"params":{
"th":1,
"xpath_expr":"/config-monitor:config-monitor/report-files/size"
}
}'
{
"jsonrpc": "2.0",
"result": {
"current_position": 1,
"total_number_of_results": 4,
"number_of_results": 4,
"number_of_elements_per_result": 1,
"results": [
["89"],
["449"],
["1852"],
["2511"]
]
},
"id": 1
}

 asa

Maybe @Akira Iwamoto can answer this question.