2

I want to create my own MIB. I'm struggling on this from couple of weeks. I followed this tutorial and using net-snmp 5.7.3. What I'm doing is:

My setup: I have two VM's, both Ubuntu 16, one is snmp-server with IP:192.168.5.20 and the other snmp-agent with IP:192.168.5.21. I wrote a MIB, which compiles good without any error (This compilation is done only on the agent system, not on the server). I have already done this:

root@snmp-agent:# MIBS=+MAJOR-MIB    
root@snmp-agent:# MIBS=+DEPENDENT-MIB    
root@snmp-agent:# export MIBS    
root@snmp-agent:# MIBS=ALL

My MIB files are in this path: /usr/share/snmp/mibs which is the default search path. I've already compiled it and generated .c and .h files successfully with the command: mib2c -c mib2c.int_watch.conf objectName. And than configured the snmp like this:

root@snmp-agent:# ./configure --with-mib-modules="objectName"
root@snmp-agent:# make
root@snmp-agent:# make install    

Everything worked fine. After this when I do (on the agent) snmptranslate I get the output as:

root@snmp-agent:snmptranslate -IR objectName.0
MAJOR-MIB::objectName.0

And with the command snmptranslate -On objectName.0 I get output as:

root@snmp-agent:# snmptranslate -On MAJOR-MIB::objectName.0
.1.3.6.1.4.1.4331.2.1.0

So, I'm getting the expected outputs on the agent system. Now my problem is I don't know how to get the same values from my server!

When I run snmpget, from the server, I get this error:

root@snmp-server:# snmpget -v2c -c public 192.168.5.21 MAJOR-MIB::objectName.0
MAJOR-MIB::objectName.0 = No Such Instance currently exists at this OID

Output when specified the OID:

root@snmp-server:# snmpget -v2c -c public 192.168.5.21 .1.3.6.1.4.1.4331.2.1
SNMPv2-SMI::enterprises.4331.2.1 = No Such Instance currently exists at this OID

Output when I do these:

root@snmp-server:# snmpget -v2c -c public 192.168.5.21 sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux snmp-agent 4.10.0-33-generic #37~16.04.1-Ubuntu SMP Fri Aug 11 14:07:24 UTC 2017 x86_64

root@snmp-server:# snmpwalk -v2c -c public 192.168.5.21 .1.3.6.1.4.1.4331.2.1
SNMPv2-SMI::enterprises.4331.2.1 = No more variables left in this MIB View (It is past the end of the MIB tree)

I have searched it and still searching but no luck. What should I do? How should I use snmpget from my server on my own MIBs? I mean something like I do with sysDescr.0 from my server.

I want to do this: snmpget 192.168.5.21 myObjectName.0 and get the values.

EDIT: I have already seen these answers, but doesn't works. snmp extend not working and snmp no such object...

UPDATE 2:

When I do snmpwalk on server:

snmp-server:# snmpwalk -v 2c -c ncs -m DISMAN-PING-MIB 192.168.5.21 .1.3.6.1.2.1.80
DISMAN-PING-MIB::pingObjects.0 = INTEGER: 1
DISMAN-PING-MIB::pingFullCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = STRING: "/bin/echo"
DISMAN-PING-MIB::pingMinimumCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = ""
DISMAN-PING-MIB::pingCompliances.4.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = ""
DISMAN-PING-MIB::pingCompliances.5.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 5
DISMAN-PING-MIB::pingCompliances.6.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 1
DISMAN-PING-MIB::pingCompliances.7.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 1
DISMAN-PING-MIB::pingCompliances.20.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 4
DISMAN-PING-MIB::pingCompliances.21.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 1
DISMAN-PING-MIB::pingIcmpEcho.1.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = ""
DISMAN-PING-MIB::pingIcmpEcho.2.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = ""
DISMAN-PING-MIB::pingIcmpEcho.3.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 1
DISMAN-PING-MIB::pingIcmpEcho.4.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = INTEGER: 0
DISMAN-PING-MIB::pingMIB.4.1.2.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48.1 = ""

When I do snmpget with pingFullCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48:

root@snmp-server:# snmpget 192.168.5.21 DISMAN-PING-MIB::pingFullCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48
DISMAN-PING-MIB::pingFullCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 = Wrong Type (should be INTEGER): STRING: "/bin/echo"

So where am I going wrong? And what is pingFullCompliance.15.46.49.46.51.46.54.46.49.46.50.46.49.46.56.48 ? Why such a long OID?

Where am I going wrong? Can anyone point me in the right direction? Any suggestions are greatly appreciated.

2 Answers2

0

The name lookup in the MIB works fine, the query works fine, but the agent responds that no such object exists. So the problem is on the agent side.

As @ransh suggests in the other answer, this may be an issue of agentx being misconfigured -- the main agent needs to query your subagent for the object being requested, and for that to happen it needs a mapping from the subtree OID to the subagent.

For scalar values like sysDescr.0, the table only has one row and one column, and the key is a dummy 0, but for other objects you need to address a specific column and row. The column number is fixed, as it is defined in the MIB, but rows aren't numbered, as these would not be persistent, and instead use the unique primary key.

For example, the IPv4 routing table can contain an arbitrary number of entries, but no two entries can have the same destination address and netmask, so this is used as the unique index (and primary key) for table lookups, and row addresses are generated from these, e.g.

.0.0.0.0.0.0.0.0              the default route (destination 0.0.0.0/0)
.192.168.0.0.255.255.255.0    the internal network (destination 192.168.0.0/24)

The DISMAN-PING-MIB uses a string as an index here, which is encoded as length and value -- length first so that a shorter string is not accidentally a prefix of a longer string. You may notice that the first element is 15, and 15 more elements follow.

To look at the table as a table, use the snmptable command.

Simon Richter
  • 3,209
  • 17
  • 17
0

I had the exact same issue, It didn't work with 5.6.2.

How I solved it:

I've upgraded to 5.7.3 , then it started working. you need to take care for the following:

  1. configure the package (on build) to support agentx) with --with-mib-modules=agentx this is my configure:

      ./configure --prefix=/usr --build=i386-linux --host=arm-linux --target=arm-linux --with-ar=arm-arago-linux-gnueabi-ar --with-cc=arm-arago-linux-gnueabi-gcc --with-ld=arm-arago-linux-gnueabi-ld --with-cflags="-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp" --with-endianness=big --with-ldflags=-Bstatic --enable-mini-agent --with-mib-modules="mibII ip-mib if-mib tcp-mib udp-mib ucd_snmp target agent_mibs notification-log-mib snmpv3mibs notification agentx" --without-openssl --without-perl-modules --disable-embedded-perl --disable-shared --with-default-snmp-version="2" --with-sys-contact="root" --with-sys-location="unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp" --disable-manuals
    
  2. add agentx to snmpd.conf This is my snmpd.config

    master  agentx
    
    rocommunity public rwcommunity private
    
    com2sec readonly  default         public 
    com2sec readwrite default     private
    
  3. started snmpd with debug, to give more details:

    snmpd -f -Lo: -Dagentx
    
  4. Then start the agentx application

The following tutorial also helped:

http://net-snmp.sourceforge.net/wiki/index.php/TUT:Writing_a_Subagent

ransh
  • 103
  • 3