Bluehost.com Web Hosting $6.95

Re: can i add a new oid and modify it in my own program?

This is a discussion on Re: can i add a new oid and modify it in my own program? within the SNMP Users forums, part of the Networking and Network Related category; This is a multi-part message in MIME format. --------------030002020707080306000505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Users

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-20-2005
Danny Milosavljevic
 
Posts: n/a
Default Re: can i add a new oid and modify it in my own program?

This is a multi-part message in MIME format.
--------------030002020707080306000505
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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


--------------030002020707080306000505
Content-Type: text/x-vcard; charset=utf-8;
name="danny.milosavljevic.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="danny.milosavljevic.vcf"

begin:vcard
fn:Danny Milosavljevic
n:Milosavljevic;Danny
org:Fabalabs Software GmbH
adr:;;Honauerstrasse 4;Linz;;4020;Austria
email;internet:danny.milosavljevic@fabalabs.org
title:Research & Development
x-mozilla-html:FALSE
version:2.1
end:vcard


--------------030002020707080306000505--


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0