SNMP MIBs and SNMP OIDs explained

Network challenges can severely impact productivity of any organization: If communication between employees and teams is disrupted, tasks will take longer to complete. Network issues also affect the overall performance of deployed applications, and user experience will suffer as a result.

Problematic network devices are a common source of network problems. This article will show how to troubleshoot issues with your network devices using PySNMP.

Top 7 issues that cause network failure

Network disruptions can occur due to hardware failure or network congestion. In this section, we will cover the seven most common problems that lead to network failures.

1. Hardware failures

Network devices like routers, modems, and switches can suffer component malfunctions or electricity problems. Hardware failures can lead to network issues, including lost internet connections or slow performance.

To prevent network hardware failures, you should monitor your devices and replace them according to the device manufacturer’s instructions.

2. Firmware problems

Network devices rely on firmware to operate effectively. Software bugs, compatibility issues, or outdated firmware can lead to network failures.

To mitigate network firmware issues, you should regularly update your firmware and check for compatibility issues integrating your device with other devices.

3. Configuration error

Incorrectly configured network devices can cause several types of network failures. For example, a misconfigured access list (ACL) in layer 3 network devices (routers, firewalls) can inadvertently block legitimate traffic or allow unauthorized access, leading to network disruptions and security vulnerabilities. Spanning Tree Protocol (STP) misconfiguration in layer 2 network devices (switches, hubs) can lead to network loops and broadcast storms that cause network instability.

To prevent configuration errors, double-check the instructions for your network devices before setting them up.

4. Cable problems

Problems with cables can also lead to network connectivity issues. For example, your cables and network connectors might be from different manufacturers and therefore incompatible; or the signal in your cables could be interrupted due to magnetic fields generated by nearby electric wires.

To prevent issues stemming from cable setup, make sure that your cables and the connectors are compatible and that your cables are placed a sufficient distance from electric wiring.

5. Routing issues

Routing failures occur when network devices fail to properly forward data packets to their intended destinations. These failures happen due to a lack of alternative routing paths when the primary paths are not available or as a result of network outages.

To prevent routing issues, set up alternative routing paths and regularly monitor your network devices to detect problems promptly.

6. Network congestion

When network devices become overloaded with data packets, they may drop packets or fail to deliver them on time, causing network connectivity problems. To prevent network congestion issues, you can set up a load balancer system to evenly distribute your network requests.

7. Wireless network interference

Wireless networks can suffer from interference issues that result in degraded performance or intermittent connectivity. Physical barriers like dense walls or furniture between network devices are common culprits.

To reduce wireless network interference, make sure you have an appropriate number of devices using the same network.

Using PySNMP

The PySNMP tool is a Python library that allows you to communicate and manipulate network devices using Simple Network Management Protocol (SNMP). It provides high-level and low-level interaction with SNMP, allowing you to flexibly monitor and interact with your network devices.

In addition, PySNMP supports SNMPv1, SNMPv2c, and the latest version, SNMPv3, which means you can easily integrate PySNMP with your existing applications. You can also integrate the PySNMP tool with other applications and receive alerts if the devices are not accessible or get overloaded with too many tasks.

Troubleshooting network failures with PySNMP

Follow these steps when using PySNMP to troubleshoot and resolve network failures:

  • Monitor the devices: Use PySNMP to monitor connected devices and check for network connectivity problems. If you can’t access your devices or notice any odd metrics, it could be an indication of a problem with your devices. Monitoring devices using PySNMP requires extensive programming and takes a long time to establish. Site24x7 network devices’ monitoring feature allows you to monitor your network devices in real time, offering a highly effective, yet quick and easy solution.
  • Hypothesis: Consider the many possible roots of device problems, including hardware and firmware issues. You should also revise any recent changes made to the network.
  • Test your hypotheses: Once you have a list of the network items to check, you can test each hypothesis to identify the exact source of the problem.
  • Find the solution: After finding the root cause of the network issue, you can turn your focus to finding the right solution, which can include upgrading firmware or buying a new device. In general, there are two basic types of solutions: temporary solutions and ones that permanently solve the problem. If you are pressed for time, you can opt for a temporary solution, but it’s advisable to follow it up with a lasting fix.
  • Check if the issue was resolved: After fixing the problem, you should monitor your devices to see if the network issue has been completely resolved.

Using PySNMP to interact with simulated devices

Let’s look at an example to demonstrate how to troubleshoot network devices using PySNMP.

We will use PySNMP to collect information about a simulated router, with information including its description, the time since the device configuration was updated, and the uptime of the device.

Run the simulated device

Let’s start by running the simulated router device using snmpsimtool, a Python command line. Open your terminal and run the following command to create a new virtual environment in Python:

mkdir ~/Projects/snmp-simulation -p 
cd ~/Projects/snmp-simulation
virtualenv venv
source venv/bin/activate
pip install snmpsim

To simulate a router device, you must have the network-routed data directory. There’s an SNMP data simulation available at the snmpsim-data repository. Clone this repository to your local environment using a new terminal:

cd ~/Projects 
git clone https://github.com/etingof/snmpsim-data.git
cd snmpsim-data/data/network/router
pwd

Save the value of the absolute path to the router directory inside the cloned snmpsim-data repository.

Note: You need to extract the “*.bz2” file of the router that you want to simulate.

Return to the open terminal in the ~Projects/snmp-simulation directory. The following command with the data-dir path value is the absolute path to the above router directory:


snmpsimd.py --data-dir=path/to/router/data --agent-udpv4-endpoint=127.0.0.1:1161

The simulated device should now be up and running. Next, collect the MIB/OID information of the simulated router device to obtain the relevant system information.

Collect the MIB/OID information

Install the snmpwalk tool on your machine to collect the MIB/OID information. You can install it on Windows, Linux, or MacOS. Below is the installation command for snmpwalk, which is part of the snmp package for the Ubuntu machine:

sudo apt update 
sudo apt install snmp

SNMP1/v2c

Run the following command to get the OID information of the network device with SNMP1/v2c configuration:

snmpwalk -v2c -c ${community-name} 127.0.0.1:161

SNMPv3

Run the following command to get the OID information of the network device with SNMPv3 configuration, MD5 authentication type, and DES encryption type:

snmpwalk -v3 -l authPriv -u ${username} -a MD5 -A 
{authentication-key}-x DES -X ${encryption-private-key}-n
${context-name} 127.0.0.1:161

You should have all the MIB/OID information in your console for the device. Let’s now use this to find out more about the device system, the device uptime, and the IP address it’s working on.

Add PySNMP code for information about the router device

Now open up a new terminal and activate the virtual environment in Python:

mkdir ~/Projects/snmp-script -p 
cd ~/Projects/snmp-script
virtualenv venv
source venv/bin/activate
pip install pysnmp

Create a new file named original.py and copy the following into it.

SNMP1/v2c

# Get information of devices  
from pysnmp.hlapi import *

iterator = getCmd(
SnmpEngine(),
CommunityData('${community-name}', mpModel=0),
UdpTransportTarget(('localhost', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.8.0')),
ObjectType(ObjectIdentity('.1.3.6.1.2.1.1.3.0')),
ObjectType(ObjectIdentity('.1.3.6.1.2.1.2.2.1.9.1')),

ObjectType(ObjectIdentity('1.3.6.1.2.1.3.1.1.3.2.1.195.218.254.97')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.4.31.1.1.3.1')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.6.9.0'))
)

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
if errorIndication: # SNMP engine errors
print(errorIndication)
else:
if errorStatus: # SNMP agent errors
print('%s at %s' % (errorStatus.prettyPrint(),
varBinds[int(errorIndex)-1] if errorIndex else '?'))
else:
for varBind in varBinds: # SNMP response contents
print(' = '.join([x.prettyPrint() for x in varBind]))

SNMPv3

# Get information of devices 

from pysnmp.hlapi import *

iterator = getCmd(
SnmpEngine(),
UsmUserData('${username}', '${authentication-key}',
'${encryption-private-key}'),
UdpTransportTarget(('127.0.0.1', 1161)),
ContextData('${context-name}'),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.8.0')),
ObjectType(ObjectIdentity('.1.3.6.1.2.1.1.3.0')),
ObjectType(ObjectIdentity('.1.3.6.1.2.1.2.2.1.9.1')),

ObjectType(ObjectIdentity('1.3.6.1.2.1.3.1.1.3.2.1.195.218.254.97')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.4.31.1.1.3.1')),
ObjectType(ObjectIdentity('1.3.6.1.2.1.6.9.0'))
)

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
if errorIndication: # SNMP engine errors
print(errorIndication)
else:
if errorStatus: # SNMP agent errors
print('%s at %s' % (errorStatus.prettyPrint(),
varBinds[int(errorIndex)-1] if errorIndex else '?'))
else:
for varBind in varBinds: # SNMP response contents
print(' = '.join([x.prettyPrint() for x in varBind]))

Note that the values for ObjectIdentity are the MIM/OIDs you got from using the snmpwalk command line in the previous section.

Run the original.py file to obtain router device metrics:

venv/bin/python3.11 original.py  
Router device information Fig. 1: Router device information

You will see the system description, the system's last change time, the system uptime, and other information about the router device. The time values for these metrics are displayed in a timestamp format that includes milliseconds, which is hard to read. To improve the code and make the output more legible, replace the current code from the errorIndication, errorStatus, errorIndex, varBinds = next(iterator) line in the original.py file with the following:


errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
if errorIndication: # SNMP engine errors
print(errorIndication)
else:
if errorStatus: # SNMP agent errors
print('%s at %s' % (errorStatus.prettyPrint(),
varBinds[int(errorIndex)-1] if errorIndex else '?'))
else:
for count,varBind in enumerate(varBinds): # SNMP response contents
if count in (1,2,3,5):
string_varBind=str(varBind)
result_value=string_varBind.split('= ')[1]

result_value=str(timedelta(seconds=float(result_value)/100))
print(result_value)
else:
print(' = '.join([x.prettyPrint() for x in varBind]))

Now the timestamp values of the recorded metrics are easier to read, displaying the uptime of the router device is around 14 days and 8 hours.

Retrieving the router device information in a more readable format Fig. 2: Retrieving the router device information in a more readable format

Conclusion

In this article, we have demonstrated how to use the PySNMP tool to inspect and troubleshoot your network devices efficiently. PySNMP supports all SNMP versions from v1 to v3 over multiple network protocols like ipv4 and ipv6, which makes applying it to your current network system easier.

PySNMP also supports multiple encryption methods such as MD5, SHA1/2, or AES, allowing you to monitor your devices with different SNMP user-based security models.

On the downside, applying PySNMP to monitor your devices is a time-consuming process that also requires advanced programming skills. Site24x7 network devices monitoring service offers a swift and effective alternative, with the added benefit of visualizing your device metrics.

Was this article helpful?

Related Articles

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 "Learn" portal. Get paid for your writing.

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.

Apply Now
Write For Us