A primary OID handler for a whole subtree
Sverre Moe <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <d2770528-eab7-45ab-85ab-1825f0dcd7be@zcs> |
I have created a MIB definition with the following structure:
snmptranslate -Tp -OS MYCOMPANY-APP-MIB::myCompany
+--myCompany(40463)
|
+--test(1)
|
+-- -R-- String testInfo(1)
| Textual Convention: DisplayString
+-- -R-- String testPlacementCountry(2)
| Textual Convention: DisplayString
+-- -R-- Integer32 testCounter(3)
With help from the tutorials I have created myself a MIB module from this MIB definition and a subagent.
I was trying to create a MIB module for only the root element test which would also respond to any get requests for its child elements.
Calling snmpget MYCOMPANY-APP-MIB::testInfo did not work, however calling snmpget MYCOMPANY-APP-MIB::test.0 did work.
user@linux-0lr0:~/projects/snmp-agent> snmpget -c public -v2c localhost MYCOMPANY-APP-MIB::test.0
MYCOMPANY-APP-MIB::test.0 = STRING: "UNKNOWN "
user@linux-0lr0:~/projects/snmp-agent> snmpget -c public -v2c localhost MYCOMPANY-APP-MIB::testInfo.0
MYCOMPANY-APP-MIB::testInfo.0 = No Such Instance currently exists at this OID
Could anyone point me in the right direction concerning my MIB module? Do I need to implement it in a different way and/or am I missing something?
It does not seem like request for any child elements of test are directed to its handler. Though if I register all 3 scalars with same handler method (put aside that my OID comparison does not work). Is there any other way to do this or do I really need to register all scalars this way?
The MIB module code:
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "test.h"
const oid test_oid[] = { 1,3,6,1,4,1,40463,1 };
const oid testInfo_oid[] = { 1,3,6,1,4,1,40463,1,1 };
const oid testPlacementCountry_oid[] = { 1,3,6,1,4,1,40463,1,2 };
const oid testCounter_oid[] = { 1,3,6,1,4,1,40463,1,3 };
/** Initializes the test module */
void init_test(void) {
DEBUGMSGTL(("test", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("test",
handle_test,
test_oid,
OID_LENGTH(test_oid),
HANDLER_CAN_RONLY
));
}
int handle_test(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
void* datapointer;
const oid* request_rootoid = (*reginfo).rootoid;
if (*request_ rootoid == testInfo_oid) {
char value[4] = {"test"};
datapointer = &value;
} else if (*request_ rootoid == testPlacementCountry_oid) {
char value[5] = {"test2"};
datapointer = &value;
} else if (*request_ rootoid == testCounter_oid) {
int value = 1234;
datapointer = &value;
} else {
char value[11] = {"UNKNOWN OID"};
datapointer = &value;
}
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR,
datapointer,
sizeof(datapointer));
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_test\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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