Hi,
tao miao schrieb:
hello, i' m a student of an university of china.
i want to and a new oid to the tree in my own program, and modify it
dynamic, so my program can be seen throught the snmp protocol.
i want to write three functions:
register_oid(OID oid)
string get_oid(OID oid)
set_oid(OID oid, String value)
you mean you want to register a scalar given an oid of some snmp mib
object that is already defined.
It is like this:
The snmp nodes form a tree.
The snmp oid is the path to one of the nodes, from the root onwards.
The mibs define some objects that start at particular points in the tree.
The mib definitions are read from files (in /usr/share/snmp/mibs) and
are more or less static.
An example for a small snmp tree:
http://www.cisco.com/univercd/illus/c/03/ct845603.gif (rather nice
description page, although a bit too lowlevel :)
http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/snmp.htm)
If you want to support an existing mib object (one that is already
present in /usr/share/snmp/mibs), you just use its oid (and do not need
to create a new mib file) to register a value for the mib object in your
program.
If you wanted to support new objects that are not defined yet, you would
have to create a new mib file too.
Lets asssume for the remainder of the mail that you want to support a
mib object already known.
Registration of a new scalar "instance" is:
int willchange = 7;
int * value = &willchange;
netsnmp_handler_registration* reg;
reg = netsnmp_create_handler_registration("", handler_cb,
oid,
oidlen,
HANDLER_CAN_RWRITE);
netsnmp_watcher_info *winfo = netsnmp_create_watcher_info((void*) value,
sizeof
(int),
ASN_INTEGER,
WATCHER_FIXED_SIZE);
netsnmp_register_watched_instance(reg, winfo);
when you are done with it (i.e. much much later):
netsnmp_unregister_handler(reg);
oids are represented as C style arrays:
oid foo[100];
foo[0] = 1;
foo[1] = 3;
foo[2] = 6;
foo[3] = 1;
somenetsnmpfunc(foo, 4); /* 4 -> number of items in array */
if you want to get an c style oid array from a c style string:
size_t foolen;
foolen = 100; /* sizeof(foo) / sizeof(foo[0]) */
snmp_parse_oid("1.3.6.1", foo, &foolen);
main loop is:
agent_check_and_process(1); // blocks, so kind of moot point (since
you cannot change the variable "willchange", so it won't, well, change :))
therefore: use some loop with snmp_select_info, select, snmp_read to
make it non-blocking, and change the variable "willchange" from time to
time. (I'm sure there is an example for it in the snmp_select_info docs)
(there is also a way to write a callback that will be called whenever
someone wants to read your value, and you change the value in the
callback - it depends on what exactly you want to do)
so i can register the some oid at the begin of my program and get or
set it's value later.
you register a value for the object of the mib at the path the oid tells
it to find. (I'm sure there is still something missing in that sentence,
so ... anyone else - feel free to correct me :))
can i do the Based on net-snmp api? how to ? is agentX OK?
yes, see above, yes
Thank you for your response
cheers,
Danny
begin:vcard
fn:Danny Milosavljevic
n:Milosavljevic;Danny
org:Fabalabs Software GmbH
adr:;;Honauerstrasse 4;Linz;;4020;Austria
email;internet:[EMAIL PROTECTED]
title:Research & Development
x-mozilla-html:FALSE
version:2.1
end:vcard