Dear:
I try to write a dynamically loadable object according to the http://www.net-snmp.org/.In the attachment ,there are my files.
I change the nstAgentPluginObject.c and load the Makefile,NET-SNMP-TUTORIAL-MIB.txt,nstAgentPluginObject.h from the
" http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_Dynamically_Loadable_Object".
Now,I have some questions.I use the Loading via the snmpd.conf file method:dlmod nstAgentPluginObject /path/to/nstAgentPluginObject.so.
I test the "snmptranslate -IR -Tp nstAgentPluginObject",the result is "+-- -RW- Integer32 nstAgentPluginObject(3) ".But,when I test"snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0",the result is "NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0=No such objest available on this agent at this OID".Can you help me?
/* * Note: this file originally auto-generated by mib2c using * : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $ */ #ifndef NSTAGENTPLUGINOBJECT_H #define NSTAGENTPLUGINOBJECT_H
/* * function declarations */ void init_nstAgentPluginObject(void); Netsnmp_Node_Handler handle_nstAgentPluginObject; #endif /* NSTAGENTPLUGINOBJECT_H */
#
# Warning: you may need more libraries than are included here on the
# build line. The agent frequently needs various libraries in order
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here. Instead, look at the libraries that were
# used when linking the snmpd master agent and copy those to this
# file.
#
CC=gcc
all: $(TARGETS)
gcc -g -I/usr/local/include -c -o nstAgentPluginObject.o
nstAgentPluginObject.c
gcc -g -fPIC -shared -o nstAgentPluginObject.so nstAgentPluginObject.o
clean:
rm *.so
NET-SNMP-TUTORIAL-MIB DEFINITIONS ::= BEGIN
-- A Comment!
-- IMPORTS: Include definitions from other mibs here, which is always
-- the first item in a MIB file.
IMPORTS
netSnmpExamples FROM NET-SNMP-EXAMPLES-MIB
OBJECT-TYPE, Integer32,
MODULE-IDENTITY FROM SNMPv2-SMI
MODULE-COMPLIANCE, OBJECT-GROUP FROM SNMPv2-CONF;
--
-- A brief description and update information about this mib.
--
netSnmpTutorialMIB MODULE-IDENTITY
LAST-UPDATED "200205290000Z" -- 29 May 2002, midnight
ORGANIZATION "net-snmp"
CONTACT-INFO "postal: Wes Hardaker
P.O. Box 382
Davis CA 95617
email: [email protected]
"
DESCRIPTION "A simple mib for demonstration purposes.
"
::= { netSnmpExamples 4 }
-- Define typical mib nodes, like where the objects are going to lie.
-- we'll prefix everything in this mib with nst (net snmp tutorial)
nstMIBObjects OBJECT IDENTIFIER ::= { netSnmpTutorialMIB 1 }
nstMIBConformance OBJECT IDENTIFIER ::= { netSnmpTutorialMIB 2 }
-- define 3 objects, which will all be implemented in different ways
-- within the tutorial.
nstAgentModules OBJECT IDENTIFIER ::= { nstMIBObjects 1 }
nstAgentModuleObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when compiled into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 1 }
::= { nstAgentModules 1 }
nstAgentSubagentObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. The object should be accessible
when the agentx subagent containing this object is attached.
See http://www.net-snmp.org/tutorial-5/toolkit/XXX for
further implementation details."
DEFVAL { 2 }
::= { nstAgentModules 2 }
nstAgentPluginObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. This object should be accessible
when the dynamic plugin has been loaded into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 3 }
::= { nstAgentModules 3 }
--
-- The above definitions produce a section of the mib tree that looks
-- like this (including our parent node, printed using the
-- snmptranslate command):
--
--
-- % snmptranslate -M+. -mNET-SNMP-TUTORIAL-MIB -Tp -IR netSnmpTutorialMIB
-- +-netSnmpTutorialMIB(4)
-- |
-- +-nstMIBObjects(1)
-- | |
-- | +-nstAgentModules(1)
-- | |
-- | +- -RW- Integer32 nstAgentModuleObject(1)
-- | +- -RW- Integer32 nstAgentSubagentObject(2)
-- | +- -RW- Integer32 nstAgentPluginObject(3)
-- |
-- +-nstMIBConformance(2)
-- You can then use the snmptranslate command to get the numerical or
-- textual OID representation of any piece of the tree:
-- Getting a OID:
-- % snmptranslate -M+. -mNET-SNMP-TUTORIAL-MIB -IR nstSSSecondsSinceChanged
-- .1.3.6.1.4.1.2021.13.4242.1.1.2
-- Getting a textual OID:
-- % snmptranslate -On -M+. -mNET-SNMP-TUTORIAL-MIB -IR
nstSSSecondsSinceChanged
--
enterprises.ucdavis.ucdExperimental.netSnmpTutorialMIB.nstMIBObjects.nstScalarSet.nstSSSecondsSinceChanged
-- Getting a description:
-- % snmptranslate -Td -M+. -mNET-SNMP-TUTORIAL-MIB -IR
nstSSSecondsSinceChanged
-- .1.3.6.1.4.1.2021.13.4242.1.1.2
-- SYNTAX TimeTicks
-- UNITS "1/100th Seconds"
-- MAX-ACCESS read-only
-- STATUS current
-- DESCRIPTION "This object indicates the number of 1/100th seconds since
the
-- nstSSSimpleString object has changed. If it is has never been
-- modified, it will be the time passed since the start of the
-- agent."
-- END: Don't forget this!
END
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "nstAgentPluginObject.h"
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if TIME_WITH_SYS_TIME
# ifdef WIN32
# include <sys/timeb.h>
# else
# include <sys/time.h>
# endif
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
static char location[256];
/** Initializes the nstAgentPluginObject module */
void
init_nstAgentPluginObject(void)
{
static oid nstAgentPluginObject_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 3 };
DEBUGMSGTL(("nstAgentPluginObject", "Initializing\n"));
netsnmp_register_scalar(netsnmp_create_handler_registration
("nstAgentPluginObject",
handle_nstAgentPluginObject,
nstAgentPluginObject_oid,
OID_LENGTH(nstAgentPluginObject_oid),
HANDLER_CAN_RWRITE));
}
int
handle_nstAgentPluginObject(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/*
* We are never called for a GETNEXT if it's registered as a
* "instance", as it's "magically" handled for us.
*/
static long long_ret; /* for everything else */
static time_t timep;
struct tm *p;
time(&timep);
/*
* 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.
*/
switch (reqinfo->mode) {
case MODE_GET:
// snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
// (u_char *)location
/* XXX: a pointer to the scalar's data */
// ,
// strlen(location)
/*
* XXX: the length of the data in bytes
); */
// long_ret=timep;
return 1233333;
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/*
* or you could use netsnmp_check_vb_type_and_size instead
*/
ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
if (ret != SNMP_ERR_NOERROR) {
netsnmp_set_request_error(reqinfo, requests, ret);
}
break;
case MODE_SET_RESERVE2:
/*
* XXX malloc "undo" storage buffer
*/
if (0 /* XXX if malloc, or whatever, failed: */ ) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
case MODE_SET_FREE:
/*
* XXX: free resources allocated in RESERVE1 and/or
* RESERVE2. Something failed somewhere, and the states
* below won't be called.
*/
break;
case MODE_SET_ACTION:
/*
* XXX: perform the value change here
*/
long_ret=timep;
return (u_char *) & long_ret;
if ( 0/* XXX: error? */ ) {
// netsnmp_set_request_error(reqinfo, requests, /* some error */
// );
}
break;
case MODE_SET_COMMIT:
/*
* XXX: delete temporary storage
*/
if ( 0/* XXX: error? */ ) {
/*
* try _really_really_ hard to never get to this point
*/
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_COMMITFAILED);
}
break;
case MODE_SET_UNDO:
/*
* XXX: UNDO and return to previous value for the object
*/
if ( 0/* XXX: error? */ ) {
/*
* try _really_really_ hard to never get to this point
*/
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_UNDOFAILED);
}
break;
default:
/*
* we should never get here, so this is a really bad error
*/
snmp_log(LOG_ERR,
"unknown mode (%d) in handle_nstAgentPluginObject\n",
reqinfo->mode);
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
------------------------------------------------------------------------------ Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
