net-snmp-users@lists.sourceforge.net

This is a discussion on net-snmp-users@lists.sourceforge.net within the SNMP Users forums, part of the Networking and Network Related category; Hello. I want to send traps from an application to the manager through the snmpd demon. -------------- - APPL - -localhost- --------------- - - - - v ------------------ --------------------- - SNMPD - - ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-22-2007
Eduardo Saavedra Cea
 
Posts: n/a
Default net-snmp-users@lists.sourceforge.net

Hello.
I want to send traps from an application to the manager through the
snmpd demon.

--------------
- APPL -
-localhost-
---------------
-
-
-
-
v
------------------ ---------------------
- SNMPD - - MANAGER -
- localhost - -------------> - other host -
------------------ ---------------------




For this, I modificated the example notification.c. In this case, you
send traps each 30 seconds.
When I load the module, it`s worked. The SNMPD daemon send the traps and
these are received in the host manager. My problem is that I want to
send traps within a program with a main() because I dont want to
recompile everytime or load the module, but It isnt work.
My program is shown below:


I compile doing: gcc -g -I. `net-snmp-config --cflags` -fPIC -shared
-c -o example.o example.c
gcc -g -o example example.o `net-snmp-config
--agent-libs`

What is the error???
Have this form sense???


The question is: How an application can send SNMP TRAP to Managers using
the SNMPD daemon?




/*
* start be including the appropriate header files
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

int main(int argc, char *argv[])
{

/*
* define the OID for the notification we're going to send
* NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification
*/
oid notification_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 3, 0, 1 };
size_t notification_oid_len = OID_LENGTH(notification_oid);
static u_long count = 0;

/*
* In the notification, we have to assign our notification OID to
* the snmpTrapOID.0 object. Here is it's definition.
*/
oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap);

/*
* define the OIDs for the varbinds we're going to include
* with the notification -
* NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatRate and
* NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatName
*/
oid hbeat_rate_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 2, 1, 0 };
size_t hbeat_rate_oid_len = OID_LENGTH(hbeat_rate_oid);
oid hbeat_name_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 2, 2, 0 };
size_t hbeat_name_oid_len = OID_LENGTH(hbeat_name_oid);

/*
* here is where we store the variables to be sent in the trap
*/
netsnmp_variable_list *notification_vars = NULL;
const char *heartbeat_name = "A girl named Maria";



/*
* add in the trap definition object
*/
snmp_varlist_add_variable(&notification_vars,
/*
* the snmpTrapOID.0 variable
*/
objid_snmptrap, objid_snmptrap_len,
/*
* value type is an OID
*/
ASN_OBJECT_ID,
/*
* value contents is our notification OID
*/
(u_char *) notification_oid,
/*
* size in bytes = oid length * sizeof(oid)
*/
notification_oid_len * sizeof(oid));


/*
* add in the additional objects defined as part of the trap
*/

/*snmp_varlist_add_variable(&notification_vars,
hbeat_rate_oid, hbeat_rate_oid_len,
ASN_INTEGER,
(u_char *)&heartbeat_rate,
sizeof(heartbeat_rate));*/

/*
* send the trap out. This will send it to all registered
* receivers (see the "SETTING UP TRAP AND/OR INFORM DESTINATIONS"
* section of the snmpd.conf manual page.
*/
send_v2trap(notification_vars);

/*
* free the created notification variable list
*/
snmp_free_varbind(notification_vars);
}


Thanks a lots.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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 03:17 AM.


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