SNMP Custom Service Template
v1.0.0
Table of contents
- Overview
- Versions
- Files
- Key Features
- Installation Instructions
- Testing the Installation
- Configuration
- MIB Documentation
- Customization
- Troubleshooting
- Security Notes
Overview
SNMP Custom Service Template is a template repository based on a ready-to-use SNMP (Simple Network Management Protocol) server for Linux systems (Ubuntu 22.04 and 24.04). It extends the standard SNMP daemon with a Python script, allowing you to define and serve your own SNMP OIDs and commands without modifying the SNMP server source code.
This template is designed for system integrators and developers who need to expose custom system metrics or control endpoints via SNMP, beyond what is available in standard SNMP agents. The included Python script works together with the SNMP daemon using the pass-persist mechanism, enabling you to implement any custom SNMP command or data point in Python.
Main value:
- Quickly add custom SNMP endpoints to your Linux system for integration with network monitoring tools
- No need to write C/C++ SNMP agents—just extend the provided Python script
- Leverages the standard SNMP server for authentication, security, and protocol handling, while your logic runs in Python
This approach is ideal if you want to monitor or control custom aspects of your system via SNMP, using a familiar scripting language and standard Linux SNMP infrastructure.
Versions
Table 1 - Application versions.
Version | Release date | What’s new |
---|---|---|
1.0.0 | 20.08.2025 | - Initial release of SNMP Custom Service Template. |
Files
The SNMP Custom Service Template includes the following components:
README.md --------------------------- Documentation and installation guide.
snmp_main.py ------------------------ Main SNMP agent Python script.
snmp_payload.py --------------------- SNMP payload handler and system monitoring.
snmpd.conf -------------------------- SNMP daemon configuration file.
CUSTOM-AGENT-MIB.txt ---------------- Main MIB definition file for the custom agent.
OID_list.txt ------------------------ OID reference and usage examples.
install.sh -------------------------- Installation script for SNMP packages.
test_snmp.sh ------------------------ Test script for SNMP agent.
libs/ ------------------------------- Folder with SNMP packages for different Ubuntu versions.
22.04/ -------------------------- SNMP packages for Ubuntu 22.04.
libsnmp-base_5.9.3+dfsg-1ubuntu1.4_all.deb
libsnmp40_5.9.3+dfsg-1ubuntu1.4_amd64.deb
snmp_5.9.3+dfsg-1ubuntu1.4_amd64.deb
snmpd_5.9.3+dfsg-1ubuntu1.4_amd64.deb
24.04/ -------------------------- SNMP packages for Ubuntu 24.04.
libsnmp-base_5.9.4+dfsg-1.1ubuntu3.1_all.deb
libsnmp40t64_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
snmp_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
snmpd_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
Key Features
Key features include:
- System Monitoring: CPU load, memory usage, temperature monitoring
- Service Status: Service health and uptime reporting
- Secure Access: SNMPv3 with authentication and encryption
- Standard Compliance: Compatible with any SNMP monitoring tool
- Comprehensive Logging: Detailed logging with rotation capabilities
- MIB Support: Complete MIB definitions for standard SNMP tool integration
- Easy Customization: Modular design for extending monitoring capabilities
Installation Instructions
Install SNMP packages
Install the .deb packages from the libs folder specific to your Ubuntu version:
For Ubuntu 24.04:
cd libs/24.04
sudo dpkg -i libsnmp-base_5.9.4+dfsg-1.1ubuntu3.1_all.deb
sudo dpkg -i libsnmp40t64_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
sudo dpkg -i snmp_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
sudo dpkg -i snmpd_5.9.4+dfsg-1.1ubuntu3.1_amd64.deb
For Ubuntu 22.04:
cd libs/22.04
sudo dpkg -i libsnmp-base_5.9.3+dfsg-1ubuntu1.4_all.deb
sudo dpkg -i libsnmp40_5.9.3+dfsg-1ubuntu1.4_amd64.deb
sudo dpkg -i snmp_5.9.3+dfsg-1ubuntu1.4_amd64.deb
sudo dpkg -i snmpd_5.9.3+dfsg-1ubuntu1.4_amd64.deb
If you encounter dependency issues:
sudo apt-get install -f
Verify the installation:
dpkg -l | grep snmp
Stop the SNMP service
sudo systemctl stop snmpd.service
Deploy the custom SNMP agent
Create the application directory:
sudo mkdir -p /opt/snmp-agent
Copy the Python scripts:
sudo cp snmp_main.py /opt/snmp-agent/
sudo cp snmp_payload.py /opt/snmp-agent/
Make scripts executable:
sudo chmod +x /opt/snmp-agent/snmp_main.py
sudo chmod +x /opt/snmp-agent/snmp_payload.py
Configure the SNMP daemon
Replace /etc/snmp/snmpd.conf
with the provided configuration:
sudo cp snmpd.conf /etc/snmp/snmpd.conf
Configure the service to run as root
Edit the systemd service file:
sudo nano /lib/systemd/system/snmpd.service
Remove -u Debian-snmp -g Debian-snmp
from the ExecStart
line.
Create the log directory
sudo mkdir -p /var/log/snmp-agent
sudo chmod 755 /var/log/snmp-agent
Start the service
sudo systemctl daemon-reload
sudo systemctl enable snmpd.service
sudo systemctl start snmpd.service
Testing the Installation
Test the SNMP service:
# Test service status
snmpget -v3 -u snmpuser -l authPriv -a SHA -A "SecurePass123" -x AES -X "SecurePass123" localhost .1.3.6.1.4.1.12345.2.4
# Test system uptime
snmpget -v3 -u snmpuser -l authPriv -a SHA -A "SecurePass123" -x AES -X "SecurePass123" localhost .1.3.6.1.4.1.12345.2.5
# Test CPU load
snmpget -v3 -u snmpuser -l authPriv -a SHA -A "SecurePass123" -x AES -X "SecurePass123" localhost .1.3.6.1.4.1.12345.2.3.1
Automated Testing Script
You can also use the provided test_snmp.sh
script to automatically test your SNMP agent setup and all custom OIDs.
Make the script executable (if needed):
chmod +x test_snmp.sh
Run the script:
./test_snmp.sh
The script will:
- Check if
snmpget
is installed and if thesnmpd
service is running - Test basic SNMP connectivity
- Test all custom OIDs (service status, uptime, CPU load, memory, temperature)
- Perform an SNMP walk on your custom OID tree
- Print a summary of the results
If all tests pass, your SNMP agent is working correctly!
Configuration
SNMP Credentials
- Username:
snmpuser
- Auth Protocol: SHA
- Auth Password:
SecurePass123
- Privacy Protocol: AES
- Privacy Password:
SecurePass123
Custom OID Tree
Base OID: .1.3.6.1.4.1.12345.2
Available endpoints:
.1.3.6.1.4.1.12345.2.4
- Service Status.1.3.6.1.4.1.12345.2.5
- System Uptime.1.3.6.1.4.1.12345.2.3.1
- CPU Load Averages.1.3.6.1.4.1.12345.2.3.2
- Memory Usage.1.3.6.1.4.1.12345.2.3.3
- CPU Temperature
MIB Documentation
The template includes comprehensive Management Information Base (MIB) files for integration with standard SNMP monitoring tools.
MIB Files
The service includes custom MIB definitions for SNMP monitoring:
- CUSTOM-AGENT-MIB.txt: Main MIB definition file for the custom SNMP agent
- Enterprise OID:
.1.3.6.1.4.1.12345
- Custom Agent Base:
.1.3.6.1.4.1.12345.2
OID Structure
.1.3.6.1.4.1.12345.2 (customAgent)
├── .4 (serviceStatus)
├── .5 (systemUptime)
└── .3 (systemInfo)
├── .1 (cpuLoadAverages)
├── .2 (memoryUsage)
└── .3 (cpuTemperature)
Installing MIB Files
To use MIB files with SNMP tools:
Copy MIB files to system directory:
sudo cp CUSTOM-AGENT-MIB.txt /usr/share/snmp/mibs/
Or specify MIB directory when using SNMP tools:
snmpget -M +. -m CUSTOM-AGENT-MIB -v3 -u snmpuser -l authPriv \
-a SHA -A "SecurePass123" -x AES -X "SecurePass123" \
localhost serviceStatus.0
Using Symbolic Names
With properly installed MIBs, you can use symbolic names instead of numeric OIDs:
# Instead of: .1.3.6.1.4.1.12345.2.4
snmpget -v3 -u snmpuser -l authPriv -a SHA -A "SecurePass123" \
-x AES -X "SecurePass123" localhost serviceStatus.0
# Instead of: .1.3.6.1.4.1.12345.2.3.1
snmpget -v3 -u snmpuser -l authPriv -a SHA -A "SecurePass123" \
-x AES -X "SecurePass123" localhost cpuLoadAverages.0
MIB Validation
Validate MIB syntax using:
smilint CUSTOM-AGENT-MIB.txt
Install smilint if needed:
sudo apt-get install libsmi2-dev libsmi2-common
Enterprise Number Registration
To customize for your organization:
- Get your enterprise number from IANA
- Replace
12345
with your registered enterprise number in the MIB file - Update organization info (ORGANIZATION and CONTACT-INFO fields) in the MIB file
- Add new objects by defining additional OBJECT-TYPE entries as needed
- Update descriptions (DESCRIPTION fields) for your specific use case
Customization
Changing the Enterprise OID
- Edit
snmp_payload.py
and changeBASE_OID
- Edit
snmpd.conf
and update thepass_persist
line - Update the MIB file
CUSTOM-AGENT-MIB.txt
with your enterprise number - Update your monitoring tools configuration accordingly
Adding New Monitoring Points
- Add new functions in
snmp_payload.py
- Update the
get_board_option()
function to handle new OID endpoints - Update the MIB file
CUSTOM-AGENT-MIB.txt
to document the new endpoints - Test new endpoints with SNMP tools
Changing Authentication
- Edit
snmpd.conf
- Update the
createUser
line with new credentials - Update the
rouser
line accordingly
Troubleshooting
Check the service status
sudo systemctl status snmpd.service
View logs
# SNMP daemon logs
sudo journalctl -u snmpd.service -f
# Custom agent logs
sudo tail -f /var/log/snmp-agent/SNMP.log
Test the connectivity
# Test if SNMP is listening
sudo netstat -ulnp | grep :161
# Test basic SNMP response
snmpget -v2c -c public localhost .1.3.6.1.2.1.1.1.0
Security Notes
- Change default passwords in production
- Consider firewall rules for port 161
- Use strong authentication credentials
- Regularly update SNMP packages
- Monitor access logs for unauthorized attempts