{"id":22815885,"url":"https://github.com/guycole/snmp-lab","last_synced_at":"2025-03-30T22:28:57.317Z","repository":{"id":267191571,"uuid":"899288291","full_name":"guycole/snmp-lab","owner":"guycole","description":"Experiments extending the Net-SNMP agent","archived":false,"fork":false,"pushed_at":"2024-12-09T01:27:33.000Z","size":30,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T03:39:49.338Z","etag":null,"topics":["c","net-snmp","net-snmp-extension","snmp","snmp-agent","snmpd"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guycole.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-06T00:59:04.000Z","updated_at":"2024-12-09T01:25:08.000Z","dependencies_parsed_at":"2024-12-09T00:21:02.051Z","dependency_job_id":"88a78418-0ef6-4f42-8424-1325e23d6dcc","html_url":"https://github.com/guycole/snmp-lab","commit_stats":null,"previous_names":["guycole/snmp-lab"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guycole%2Fsnmp-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guycole%2Fsnmp-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guycole%2Fsnmp-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guycole%2Fsnmp-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guycole","download_url":"https://codeload.github.com/guycole/snmp-lab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246389870,"owners_count":20769459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","net-snmp","net-snmp-extension","snmp","snmp-agent","snmpd"],"created_at":"2024-12-12T14:05:34.980Z","updated_at":"2025-03-30T22:28:57.273Z","avatar_url":"https://github.com/guycole.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snmp-lab\nExperiments extending the Net-SNMP agent\n\n## Introduction\nThis project is to share my experience in extending the [Net-SNMP](https://en.wikipedia.org/wiki/Net-SNMP) agent by creating a custom [MIB](https://en.wikipedia.org/wiki/Management_information_base) and then populating the generated stubs from mib2c(1).\n\nI am writing this in November, 2024 and the current source version of Net-SNMP is 5.9.4, my development box is a ThinkPad on Ubuntu 22 LTS (Jammy Jellyfish).\n\n## Building Net-SNMP from scratch\n1. Obtain and unpack the source tar ball.\n1. ./configure (there will be interactive questions)\n    1. I use SNMPv2c for development and use SNMPv3 for production.\n    1. My configuration summary:\n\n    ```\n    ---------------------------------------------------------\n                Net-SNMP configuration summary:\n    ---------------------------------------------------------\n\n      SNMP Versions Supported:    1 2c 3\n      Building for:               linux\n      Net-SNMP Version:           5.9.4.pre2\n      Network transport support:  Callback Unix Alias TCP UDP TCPIPv6 UDPIPv6 IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase IPBase IPv6Base\n      SNMPv3 Security Modules:     usm\n      Agent MIB code:            default_modules =\u003e  snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host\n      MYSQL Trap Logging:         unavailable\n      Embedded Perl support:      enabled\n      SNMP Perl modules:          building -- embeddable\n      SNMP Python modules:        disabled\n      Crypto support from:        use_pkg_config_for_openssl\n      Authentication support:     MD5\n      Encryption support:         \n      Local DNSSEC validation:    disabled\n\n    ---------------------------------------------------------\n    ```\n\n1. make;sudo make install\n    1. binaries installed in /usr/local/bin and /usr/local/sbin\n    1. headers installed in /usr/local/include/net-snmp\n    1. libraries installed in /usr/local/lib\n    1. mib installed in /usr/local/share/snmp/mibs\n\n1. configuration files for snmp utilities and snmpd\n    1. configuration files reside in /usr/local/share/snmp\n    1. examples:\n        [snmp.conf (utilities)](https://github.com/guycole/snmp-lab/blob/main/config/snmp.conf)\n        [snmpd.conf (snmpd)](https://github.com/guycole/snmp-lab/blob/main/config/snmpd.conf)\n    1. copy these or use snmpconf(1) to generate your own\n\n1. almost there!\n    1. snmpd(8) does not install as a systemd service\n    1. logs to /var/log/snmpd.log\n\n## Test run vanilla agent\n1. (optional) I like to run tcpdump(8) to see the agent traps.\n    1. Ensure snmpd.conf has the correct IP address for your \"manager\" (i.e. development machine)\n    1. ```tcpdump -v port 162```\n\n1. Run snmpd\n    1. Must run as root for port 161\n    1. I prefer to run snmpd(8) in the foreground while developing\n    1. Start the agent like ```./snmpd -f -V```\n    1. Should have observed the start trap (via tcpdump)\n\n1. Tail the log\n    1. ```tail -f /var/log/snmpd.log```\n    1. Should a version message waiting for you\n\n1. Exercise the agent\n    1. ```snmpwalk -v 2c -c public localhost system```\n    1. You should see something like this:\n        ```\n        gsc@waifu:138\u003esnmpwalk -v 2c -c public localhost system\n        MODULE-IDENTITY MACRO (lines 55..79 parsed and ignored).\n        OBJECT-IDENTITY MACRO (lines 81..103 parsed and ignored).\n        OBJECT-TYPE MACRO (lines 212..298 parsed and ignored).\n        NOTIFICATION-TYPE MACRO (lines 302..334 parsed and ignored).\n        TEXTUAL-CONVENTION MACRO (lines 8..48 parsed and ignored).\n        SNMPv2-MIB::sysDescr.0 = STRING: Linux waifu 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov  6 17:42:15 UTC 2 x86_64\n        SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10\n        DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (14624) 0:02:26.24\n        SNMPv2-MIB::sysContact.0 = STRING: mongohax\n        SNMPv2-MIB::sysName.0 = STRING: waifu\n        SNMPv2-MIB::sysLocation.0 = STRING: margaritaville\n        SNMPv2-MIB::sysServices.0 = INTEGER: 12\n        SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance\n        SNMPv2-MIB::sysORID.2 = OID: SNMP-MPD-MIB::snmpMPDCompliance\n        SNMPv2-MIB::sysORID.3 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance\n        SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB\n        SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup\n        SNMPv2-MIB::sysORID.6 = OID: TCP-MIB::tcpMIB\n        SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB\n        SNMPv2-MIB::sysORID.8 = OID: IP-MIB::ip\n        SNMPv2-MIB::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance\n        SNMPv2-MIB::sysORID.10 = OID: NOTIFICATION-LOG-MIB::notificationLogMIB\n        SNMPv2-MIB::sysORDescr.1 = STRING: The SNMP Management Architecture MIB.\n        SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.\n        SNMPv2-MIB::sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.\n        SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities\n        SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.\n        SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing TCP implementations\n        SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations\n        SNMPv2-MIB::sysORDescr.8 = STRING: The MIB module for managing IP and ICMP implementations\n        SNMPv2-MIB::sysORDescr.9 = STRING: The MIB modules for managing SNMP Notification, plus filtering.\n        SNMPv2-MIB::sysORDescr.10 = STRING: The MIB module for logging SNMP Notifications.\n        SNMPv2-MIB::sysORUpTime.1 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.2 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.3 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.4 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.5 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.6 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.7 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.8 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.9 = Timeticks: (0) 0:00:00.00\n        SNMPv2-MIB::sysORUpTime.10 = Timeticks: (0) 0:00:00.00\n        ```\n\n    1. If all this works out, congratulations you have built a working snmpd (agent).\n\n## Extend the agent to support a custom MIB\n1. In this section, I use a simple custom MIB to generate C stubs via [mib2c(1)](https://net-snmp.sourceforge.io/tutorial/tutorial-5/toolkit/mib2c/index.html) and then add these to snmpd, followed by verification via snmpwalk(1).\n\n## Demo MIB\n1. Start off simple with two scalars in [GUY-COLE-SCALAR-MIB](https://giithub.com/guycole/snmp-lab/blob/main/mib/GUY-COLE-SCALAR-MIB.txt).  \n1. Copy GUY-COLE-SCALAR-MIB.txt to /usr/local/share/snmp/mibs\n1. Seed your environment: ```export MIBS=\"+GUY-COLE-SIMPLE-MIB\"```\n1. Validate: ```snmptranslate -IR guyColeSimple``` (should run without error).\n1. Run mib2c(1): ```mib2c guyCole```\n    1. The OID 1.3.6.1.4.1.5088 is based on my IANA enterprise assignment.\n    1. Pick \"Net-SNMP style code\"\n    1. Pick \"writing code for generic some scalars\"\n    1. Generates two files: \"guyCole.h\" and guyCole.c\"\n1. Configure and build snmpd(8) for new MIB\n    1. Copy the generated files to the Net-SNMP directory, i.e. \"net-snmp-5.9.4/agent/mibgroup\"\n    1. Run configure again: ```./configure --with-mib-modules=\"guyCole\"```\n    1. My configuration summary:\n    ```\n    ---------------------------------------------------------\n                Net-SNMP configuration summary:\n    ---------------------------------------------------------\n\n      SNMP Versions Supported:    1 2c 3\n      Building for:               linux\n      Net-SNMP Version:           5.9.4.pre2\n      Network transport support:  Callback Unix Alias TCP UDP TCPIPv6 UDPIPv6 IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase IPBase IPv6Base\n      SNMPv3 Security Modules:     usm\n      Agent MIB code:            default_modules guyCole =\u003e  snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host\n      MYSQL Trap Logging:         unavailable\n      Embedded Perl support:      enabled\n      SNMP Perl modules:          building -- embeddable\n      SNMP Python modules:        disabled\n      Crypto support from:        use_pkg_config_for_openssl\n      Authentication support:     MD5\n      Encryption support:         \n      Local DNSSEC validation:    disabled\n\n    ---------------------------------------------------------\n    ```\n    1. make;sudo make install\n1. Exercise the agent \n    1. Restart the agent with logging enabled\n        1. ```./snmpd -DguyCole -f -V``` \n    1. Invoke snmpwalk(1)\n        ```\n        gsc@waifu:355\u003esnmpwalk -v 2c -c public localhost 1.3.6.1.4.1.5088.1.1\n        SNMPv2-SMI::enterprises.5088.1.1.0 = INTEGER: 0\n        ```\n    1. Set fresh integer value using snmpset(1)\n        ```\n        snmpset -v 2c -c private localhost 1.3.6.1.4.1.5088.1.1.0 i 5\n        SNMPv2-SMI::enterprises.5088.1.1.0 = INTEGER: 5\n        ```\n    1. Verify update\n        ```\n        snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.5088.1.1\n        SNMPv2-SMI::enterprises.5088.1.1.0 = INTEGER: 5\n        ```\n\n  476  snmpset -v 2c -c private localhost 1.3.6.1.4.1.5088.1.2.0 s \"aaaaa\"\n  477  snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.5088.1\n\n\n[Net-SNMP Coding Documentation](https://net-snmp.sourceforge.io/dev/agent/index.html)\nhttp://www.net-snmp.org/wiki/index.php/Agent_Architecture\nhttps://openhpi.sourceforge.net/subagent-manual/index.html","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguycole%2Fsnmp-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguycole%2Fsnmp-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguycole%2Fsnmp-lab/lists"}