Streamlit PySNMP

import streamlit as st
import pandas as pd
from pysnmp.hlapi import snmpget

Define SNMP details (replace with your community string and device IP)

community_string = “your_community_string”
device_ip = “your_device_ip”

Define OIDs to retrieve (replace with relevant OIDs for your device)

oids = [“sysUpTime”, “sysDescr”, “ifDescr.1”] # OIDs for uptime, description, and interface description

def get_snmp_data():
“”“Fetches SNMP data from the device and returns a dictionary”“”
result = {}
for oid in oids:
try:
errorIndication, errorStatus, errorIndex, varBinds = snmpget(
community=community_string,
hostname=device_ip,
oid=oid
)
if errorIndication:
st.error(f"Error: {errorIndication}“)
elif errorStatus:
st.error(f"Error at OID {oid}: {errorStatus}”)
else:
for varBind in varBinds:
name, val = varBind
result[name.decode(‘utf-8’)] = val.decode(‘utf-8’)
except Exception as e:
st.error(f"SNMP Error: {e}")
return result

Get SNMP Data

snmp_data = get_snmp_data()

Convert data to Pandas DataFrame

df = pd.DataFrame.from_dict(snmp_data, orient=‘index’, columns=[‘Value’])

Streamlit App Layout

st.title(“SNMP Monitoring Dashboard”)
st.subheader(f"Device: {device_ip}")

Display data in a table

st.dataframe(df)

Display additional information (optional)

st.write(“Uptime:”, snmp_data.get(“sysUpTime”))
st.write(“Device Description:”, snmp_data.get(“sysDescr”))

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.