AutoNetOps

Cover Image for Helpful Tools for Network Automation: A Practical Cheat Sheet

Helpful Tools for Network Automation: A Practical Cheat Sheet

·

4 min read

Hey there! Today we will be building a cheat sheet to facilitate using some very helpful tools for network automation. This helps us get some fast information on network devices and verify the information and formats beforehand and while debugging when scripting. Let's get to it.

The main tools that have been helpful for me lately include:

  • SSH

    • NAPALM
  • SNMP

    • NET-SNMP
  • YANG-based

    • Cisco YANG Suite

    • GNMIC/Pygnmi

    • SSH (NETCONF)

So let's start:


## NAPALM

NAPALM can be used from the CLI in addition to being integrated into Python scripts. Here’s how you can install and use it.

Installation

pip3 install napalm

Reference

NAPALM Documentation

Usage

napalm --user FAKEUSER --password FAKEPASS --vendor DRIVER IP_ADDRESS call GETTERS

Example Getter: get_facts

Result


## GNMIC

GNMIc is an important tool for interacting with network devices that support the gNMI protocol. Below is how to install and use GNMIc.

GNMIc Reference

Installation

bash -c "$(curl -sL https://get-gnmic.kmrd.dev)"

Common Commands

CAPABILITIES

Retrieve the capabilities of a gNMI-enabled device.

gnmic -a <ip:port> --username <user> --password <password> --insecure capabilities

Example:

gnmic -a 10.80.255.30:6030 -u admin -p admin --insecure capabilities

GET

Retrieve a data snapshot from the target device.

gnmic -a <ip:port> --username <user> --password <password> get --path "/components/component/state/temperature"

SET

Modify the state of the target device.

Set Command Documentation

SUBSCRIBE

Subscribe to telemetry data from the target device.

gnmic -a <ip:port> -u admin -p admin --insecure subscribe --path "/interfaces/interface[name=Management1]/state/counters"

GNMI Prompt

You can also start an interactive session with preconfigured credentials using the prompt command.

gnmic --insecure --username admin --password admin --address FAKE_IP prompt

This will make the prompt already start with the pieces of information set, for us to focus on the information-gathering


## NETSNMP

NET-SNMP is a widely used suite of tools to interact with SNMP-enabled devices.

Installation

NET-SNMP Installation and Tutorial

2. Identify the OIDs

Here are some common SNMP OIDs for interface statistics based on the standard MIB-II (RFC 1213):

ifInOctets.1.3.6.1.2.1.2.2.1.10(Bytes received on an interface)
ifOutOctets.1.3.6.1.2.1.2.2.1.16(Bytes sent out on an interface)
ifInErrors.1.3.6.1.2.1.2.2.1.14(Inbound errors)
ifOutErrors.1.3.6.1.2.1.2.2.1.20(Outbound errors)

3. Querying interface statistics

Assume you have an SNMP-enabled device (like a router or switch) with IP 192.168.1.1, using SNMP community string public.

You can run the following command to get the statistics for a specific interface (replace IF_INDEX with the interface index number, which you can find using ifDescr):

Example:

## V2
snmpget -v2c -c public 192.168.1.1 ifInOctets.IF_INDEX ifOutOctets.IF_INDEX
snmpget -v2c -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.10.IF_INDEX .1.3.6.1.2.1.2.2.1.16.IF_INDEX

## V3
snmpget -v 3 -u 'USERNAME' -a SHA -x AES -l authPriv -A 'AUTHPASS' -X 'PRIVPASS' IP_ADDRESS .1.3.6.1.2.1.1.5.0 (THIS WILL TRY TO GET THE SYSTEM NAME)


snmpget ..... SNMPv2-MIB::sysUpTime.0
snmpbulkwalk ... .1.0.8802.1.1.2.1.4.1.1.9 (Getting LLDP neighbors)

## CISCO YANGSUITE

YANG Suite is a valuable tool for working with YANG-based models.

Installation

You can install Cisco YANG Suite either via Docker or pip. Check the GitHub Repository for instructions.

Running YANG Suite

Once installed, run the suite using:

yangsuite

## SSH

It’s possible to interact with a NETCONF-enabled device using an SSH session to retrieve YANG schemas or perform NETCONF operations.

Starting a NETCONF Session

To initiate an SSH session with NETCONF, use:

ssh -s <username>@<device-ip> netconf [-p 830]

This opens a session where you can retrieve capabilities and perform operations on the device.

Not really the best way, other than getting the capability models.

## Conclusion

This cheat sheet covers some of the essential tools for network automation, from querying devices with SNMP to interacting with them using YANG-based models. Whether you are automating tasks, retrieving data, or configuring devices, these tools can help streamline your workflow.