nstAgentPluginObject.c
#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"
static int nstAgentPluginObject = 3;
void init_nstAgentPluginObject(void)
{
static oid nstAgentPluginObject_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 3, 0 };
netsnmp_register_int_instance("nstAgentPluginObject",
nstAgentPluginObject_oid,
OID_LENGTH(nstAgentPluginObject_oid),
&nstAgentPluginObject, NULL);
}
nstAgentPluginObject.h
#ifndef NSTAGENTPLUGINOBJECT_H
#define NSTAGENTPLUGINOBJECT_H
void init_nstAgentPluginObject(void);
#endif /* NSTAGENTPLUGINOBJECT_H */
build nstAgentPluginObject.so
gcc -I. `net-snmp-config --cflags` -fPIC -shared -c -o nstAgentPluginObject.o nstAgentPluginObject.c
gcc -I. `net-snmp-config --cflags` -fPIC -shared -o nstAgentPluginObject.so nstAgentPluginObject.o
add configuration like this:
dlmod nstAgentPluginObject /your_shared_object_path/nstAgentPluginObject.so
restart server
as you like^^
test nstAgentPluginObject
% snmpget -c snmp_user_id -v 1 snmp_server_name 1.3.6.1.4.1.8072.2.4.1.1.3.0
NET-SNMP-MIB::netSnmp.2.4.1.1.3.0 = INTEGER: 3
related MIB file:
NET-SNMP-TUTORIAL-MIB DEFINITIONS ::= BEGIN
IMPORTS
netSnmpExamples FROM NET-SNMP-EXAMPLES-MIB
OBJECT-TYPE, Integer32,
MODULE-IDENTITY FROM SNMPv2-SMI
MODULE-COMPLIANCE, OBJECT-GROUP FROM SNMPv2-CONF;
netSnmpTutorialMIB MODULE-IDENTITY
LAST-UPDATED "200205290000Z" -- 29 May 2002, midnight
ORGANIZATION "net-snmp"
::= { netSnmpExamples 4 }
nstMIBObjects OBJECT IDENTIFIER ::= { netSnmpTutorialMIB 1 }
nstMIBConformance OBJECT IDENTIFIER ::= { netSnmpTutorialMIB 2 }
nstAgentModules OBJECT IDENTIFIER ::= { nstMIBObjects 1 }
nstAgentModuleObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 1 }
::= { nstAgentModules 1 }
nstAgentSubagentObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 2 }
::= { nstAgentModules 2 }
nstAgentPluginObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 3 }
::= { nstAgentModules 3 }
END