Yes it is a group of scalar. In my little example it is only one group, but it 
can potentially be many groups. There will never be other groups in a group 
that has scalars, but one group can have 2 group of scalars. 

For example it could be something like this. Can all these scalar be counted in 
the main group of test , or the groups of test1 , test2 , test31 and test32 ? 
+--myCompany(40463) 
| 
+--test(1) 
| 
+--test1(1) 
| 
+-- -R-- String testInfo(1) 
| Textual Convention: DisplayString 
+-- -R-- String testPlacementCountry(2) 
| Textual Convention: DisplayString 
+-- -R-- Integer32 testCounter(3) 
+--test2(2) 
| 
+-- -R-- String testSomething(1) 
| Textual Convention: DisplayString 
+-- -R-- String testSomething2(2) 
| Textual Convention: DisplayString 
+-- -R-- Integer32 testSomething3(3) 
+--test3(3) 
| 
+--test31(1) 
| 
+-- -R-- String testSomethingMore(1) 
| Textual Convention: DisplayString 
+-- -R-- String testSomethingMore2(2) 
| Textual Convention: DisplayString 
+-- -R-- Integer32 testSomethingMore3(3) 
+--test32(2) 
| 
+-- -R-- String testSomethingElse(1) 
| Textual Convention: DisplayString 
+-- -R-- String testSomethingElse2(2) 
| Textual Convention: DisplayString 
+-- -R-- Integer32 testSomethingElse3(3) 

Thanx. I will look into the function netsnmp_register_scalar_group and see if 
it will work for what I need. 


/Sverre 

----- Original Message -----

Fra: "Dave Shield" <[email protected]> 
Til: "Sverre Moe" <[email protected]> 
Kopi: [email protected] 
Sendt: 7. september 2012 12:40:36 
Emne: Re: A primary OID handler for a whole subtree 

On 5 September 2012 09:18, Sverre Moe <[email protected]> wrote: 
> 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) 

So this is a group of scalar objects - correct? 



> 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. 

Have a closer look at the code you are using to register the OID: 

> netsnmp_register_scalar( 
> netsnmp_create_handler_registration(... test_oid ...)); 

You are telling the agent 
"here is a (single) scalar object with the oid 'test_oid' " 

The agent is therefore processing incoming requests 
based on this structure - a single scalar object 
MYCOMPANY-APP-MIB::test 
The only valid instance of a scalar object is the one with the 
subidentifier .0 - which is exactly what the agent is reporting. 


So the agent is working correctly, based on what has been 
registered. If you wish to register a set of related scalar OIDs, 
then try using 
netsnmp_register_scalar_group( 
netsnmp_create_handler_registration(.....), 
1, 3); 

which tells the agent that there are multiple scalar objects 
to register. 

There are various examples of what this sort of handler should 
look like in the 'mibgroup/mibII' code. See ip.c, udp.c, tcp.c 
for ideas 

Dave 



> 
> 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")); 
> 
> } 
> 
> 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 
> 



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

Reply via email to