First thing first. I want to create my own MIB.
Please pardon me if I'm asking a simple question as I'm a newbie to SNMP and I'm struggling on this from couple of weeks. I have already been through TUT:mib2c.
UPDATE: I've the following MIB named SAMPLE-MIB
, which compiles good without any error (This compilation is done only on the agent system, not on the server).
SAMPLE-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32,
NOTIFICATION-TYPE FROM SNMPv2-SMI
SnmpAdminString FROM SNMP-FRAMEWORK-MIB
netSnmp FROM NET-SNMP-MIB
;
sample MODULE-IDENTITY
LAST-UPDATED "201709120200Z"
ORGANIZATION "NCS"
CONTACT-INFO
"@ncs-in.com"
DESCRIPTION
"A test MIB"
REVISION "201709120200Z"
DESCRIPTION
"initial Draft"
::= { iso org(3) dod(6) internet(1) private(4) enterprises(1) 39106 }
sampleResearch OBJECT IDENTIFIER ::= { sample 2 }
sampleVar OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"testing"
::= { sampleResearch 1}
END
I have already done this:
root@snmp-agent:# MIBS=+SAMPLE-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, like this:
root@snmp-agent:# snmptranslate -On SAMPLE-MIB::sampleVar
root@snmp-agent:# snmptranslate -IR SAMPLE-MIB
root@snmp-agent:# mib2c -c mib2c.scalar.conf sampleVar
NOTE: These sampleVar.c and sampleVar.h files are in the path:
/home/snmp-agent/Desktop/project/net-snmp-5.7.3/agent/mibgroup/
.
To keep it simple I din't modify anything in the sampleVar.h
and this is how my sampleVar.c
file looks:
/*
* Note: this file originally auto-generated by mib2c using
* $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "sampleVar.h"
static int myvar=10;
/** Initializes the sampleVar module */
void
init_sampleVar(void)
{
const oid sampleVar_oid[] = { 1,3,6,1,4,1,39106,2,1 };
const size_t sampleVar_oid_len = OID_LENGTH(sampleVar_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
DEBUGMSGTL(("sampleVar", "Initializing\n"));
/* netsnmp_register_scalar(
netsnmp_create_handler_registration("sampleVar", handle_sampleVar,
sampleVar_oid, OID_LENGTH(sampleVar_oid),
&,HANDLER_CAN_RWRITE ));*/
netsnmp_register_int_instance("sampleVar",
sampleVar_oid,
OID_LENGTH(sampleVar_oid),
&myvar, NULL);
}
int
handle_sampleVar(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret = 120892;
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
struct poolTable_entry *table_entry;
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
DEBUGMSGTL(("sampleVar", "Initializing\n"));
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
return ret;
}
Now I reconfigure net-snmp with the MIB's like this:
./configure --with-mib-modules="sampleVar"
make
make install
After this when I do (on the agent) snmptranslate -IR sampleVar.0
I get the output as:
root@snmp-agent:# snmptranslate -IR sampleVar.0
SAMPLE-MIB::sampleVar.0 (expected output of the command)
And with the command snmptranslate -On objectName.0
I get output as:
root@snmp-agent:# snmptranslate -On SAMPLE-MIB::sampleVar.0
.1.3.6.1.4.1.39106.2.1 (expected output of the command)
When I do snmpwalk
on server:
snmp-server:# snmpwalk -v 2c -c ncs -m SAMPLE-MIB 192.168.5.22 .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
SAMPLE-MIB::sampleVar.3.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): ""
SAMPLE-MIB::sampleVar.4.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): ""
SAMPLE-MIB::sampleVar.5.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 5
SAMPLE-MIB::sampleVar.6.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
SAMPLE-MIB::sampleVar.7.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
SAMPLE-MIB::sampleVar.20.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 4
SAMPLE-MIB::sampleVar.21.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
But, When I do snmpget
from my server, I get:
root@snmp-server:# snmpget 192.168.5.22 sampleVar.0
SAMPLE-MIB::sampleVar = No Such Object available on this agent at this OID
root@snmp-server:# snmpget -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleResearch.3.1.2 = No Such Object available on this agent at this OID
I do get expected output for sysUpTime.0
from my server:
root@snmp-server:# snmpget 192.168.5.22 sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (721781) 2:00:17.81 (OUTPUT)
I have googled it and still searching but no luck. So anyone can tell me what to do next? How should I use snmpget
from my server on my own MIBs?
Any ideas or suggestions are highly appreciated. Thank you.
UPDATE 2: Output from snmpgetnext
:
root@snmp-server:~# snmpgetnext -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
root@snmp-server:~# snmpgetnext -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.2
SAMPLE-MIB::sample.3.1.1.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = ""
As you said: snmpget is used to target a specific OID in SNMP, So accordingly when I specify the complete OID, I get correct output:
root@snmp-server:~# snmpget -v 2c -c ncs -m SAMPLE-MIB 192.168.5.22 sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
But what is this: sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54? What's wrong here? I don't understand that! I din't specify this stuff!!!!