How to parse the output from napalm_get

when I am using nornir napalm_get or netmiko_send_command collect some output, I noticed that the data type is “nornir.core.task.AggregatedResult”. In this data structure, how to parse it? eg: if I want to filter out interface name and “remote_system_name”, how should I achieve that?

Following are my code and output:

from nornir_utils.plugins.functions import print_result
from nornir_napalm.plugins.tasks import napalm_get
from nornir_netmiko import netmiko_send_command

nr = InitNornir(config_file=“config.yml”, dry_run=True)

results = nr.run(napalm_get, getters=“get_lldp_neighbors_detail”)

print(results)
print(type(results))
print_result(results)

AggregatedResult (napalm_get): {'syd-lab-router-001': MultiResult: [Result: "napalm_get"]}
nornir.core.task.AggregatedResult
napalm_get**********************************************************************
* syd-lab-router-001 ** changed : False ****************************************
vvvv napalm_get ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
{ 'get_lldp_neighbors_detail': { 'GigabitEthernet0/0/0': [ { 'parent_interface': '',
                                                             'remote_chassis_id': '2852.61ba.fb00',
                                                             'remote_port': 'Gi1/0/23',
                                                             'remote_port_description': 'n-epcau-lab-router1-g0-0',
                                                             'remote_system_capab': [ 'bridge',
                                                                                      'router'],
                                                             'remote_system_description': 'Cisco '
                                                                                          'IOS '
                                                                                          'Software, '
                                                                                          'C2960X '
                                                                                          'Software '
                                                                                          '(C2960X-UNIVERSALK9-M), '
                                                                                          'Version '
                                                                                          '15.2(2)E5, '
                                                                                          'RELEASE '
                                                                                          'SOFTWARE '
                                                                                          '(fc2)',
                                                             'remote_system_enable_capab': [ 'bridge',
                                                                                             'router'],
                                                             'remote_system_name': 'syd-lab-mgmt-001'}],
                                 'GigabitEthernet0/2': [ { 'parent_interface': '',
                                                           'remote_chassis_id': '444c.a892.26a3',
                                                           'remote_port': 'Ethernet6',
                                                           'remote_port_description': 'n-epcau-lab-router1-g0-2',
                                                           'remote_system_capab': [ 'bridge',
                                                                                    'router'],
                                                           'remote_system_description': 'Arista '
                                                                                        'Networks '
                                                                                        'EOS '
                                                                                        'version '
                                                                                        '4.23.0.1F-2GB '
                                                                                        'running '
                                                                                        'on '
                                                                                        'an '
                                                                                        'Arista '
                                                                                        'Networks '
                                                                                        'DCS-7150S-24-CL',
                                                           'remote_system_enable_capab': [ 'bridge',
                                                                                           'router'],
                                                           'remote_system_name': 'syd-lab-arista-001'}]}}
^^^^ END napalm_get ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Process finished with exit code 0

Many thanks in advance!

Try something along the lines of…

print(results["syd-lab-router-001"][0]

This should you the get_lldp_neighbors_detail result. You can dig deeper.

print(results["syd-lab-router-001"][0]["get_lldp_neighbors_detail"]

This blog has helped me better understand this.

@jchristopher327 Thank you Jay!

I am glad my blog help :slight_smile:

In addition - if the remote host is linux, my blog post on parsing command output from Nornir using jc may be useful: https://blog.kellybrazil.com/2020/12/09/parsing-command-output-in-nornir-with-jc/