snmp_varlist_add_variable
fab casta <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I have two processes:
- one sending traps
- one receiving traps
To send the traps, I use the function snmp_varlist_add_variable : refeers to the file example.c (included file)
the questions are:
-----------------
I would like to find in the RFC, the "requirement" that precise that when a oid is added through the function snmp_varlist_add_variable (for NET-SMNP v2 if possible...)
-- if it's a simple data, the '0' must be sent.
For example if the following data sent, the 0 is compulsary
oid lruSysName_oid[] = { 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 1, 1, 1, 0 };
-- if it's a data from an array, the 'index' must be sent.
For example if the following data sent, the _index is compulsary
oid lruFaultIndex_oid[] = { 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 1, 13, 2, 1, 1, _index };
I hope i'm enought clear!!
thanks for your help
Casta
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
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
example_trap.c
(text/plain, 4.1 KB)
//! OID for snmptrap
static oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
ECODE send_lruMIBFaultTrap_trap(STD_UnsignedInteger32 p_index,
BIT_PLruFaultRecType p_faultDescript,
struct snmp_session *p_session)
{
///////////////////////
// Declaration //
///////////////////////
netsnmp_variable_list _tempList;
netsnmp_variable_list *_returnVar;
netsnmp_variable_list *var_list = NULL;
STD_SignedInteger32 _ret = 0;
STD_UnsignedInteger32 _upTime = 0;
netsnmp_pdu _pdu;
netsnmp_pdu *_pduPtr;
STD_UnsignedInteger32 _index = p_index + 1;
oid sysUptimeOid[] =
{ 1, 3, 6, 1, 2, 1, 1, 3, 0 };
oid lruMIBFaultTrap_oid[] =
{ 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 2, 1, 0, 8 };
oid lruSysName_oid[] =
{ 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 1, 1, 1, 0 };
oid lruSysIpAddress_oid[] =
{ 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 1, 1, 8, 0 };
oid lruFaultIndex_oid[] =
{ 1, 3, 6, 1, 4, 1, 16727, 2, 2, 1, 1, 13, 2, 1, 1, _index };
// Added variables
//!!!!!!!!!!!!!!!!!!!!!
// CODE DELETED : not usefull for this example
//!!!!!!!!!!!!!!!!!!!!!
/////////////////////////
// Initialization //
/////////////////////////
//!!!!!!!!!!!!!!!!!!!!!
// CODE DELETED : not usefull for this example
//!!!!!!!!!!!!!!!!!!!!!
///////////////////////
// Algorithm //
///////////////////////
// Data recoverage
//!!!!!!!!!!!!!!!!!!!!!
// CODE DELETED : not usefull for this example
//!!!!!!!!!!!!!!!!!!!!!
_pduPtr = snmp_pdu_create(SNMP_MSG_TRAP2);
if ( _pduPtr == NULL)
{
_rc = (ECODE)-1;
}
else
{
_upTime = netsnmp_get_agent_uptime();
if ( _returnVar != NULL)
{
// First put the sysuptime
_returnVar = snmp_varlist_add_variable(&var_list,
sysUptimeOid,
OID_LENGTH(sysUptimeOid),
ASN_TIMETICKS,
(u_char *)&_upTime,
sizeof(_upTime));
}
if ( _returnVar != NULL)
{
/*
* Set the snmpTrapOid.0 value
*/
_returnVar = snmp_varlist_add_variable(&var_list,
snmptrap_oid,
OID_LENGTH(snmptrap_oid),
ASN_OBJECT_ID,
(u_char *)lruMIBFaultTrap_oid,
sizeof(lruMIBFaultTrap_oid));
}
if ( _returnVar != NULL)
{
_returnVar =
snmp_varlist_add_variable(&var_list,
lruSysName_oid,
OID_LENGTH(lruSysName_oid),
ASN_OCTET_STR,
_hostName,
strnlen(_hostName,STD_STRING_CAPACITY));
}
if ( _returnVar != NULL)
{
_returnVar =
snmp_varlist_add_variable(&var_list,
lruSysIpAddress_oid,
OID_LENGTH(lruSysIpAddress_oid),
ASN_IPADDRESS,
(u_char *)&_hostIfInfo.ifTable[0].ipAddr,
sizeof(struct in_addr));
}
if ( _returnVar != NULL)
{
_returnVar =
snmp_varlist_add_variable(&var_list,
lruFaultIndex_oid,
OID_LENGTH(lruFaultIndex_oid),
ASN_INTEGER,
(u_char*)&_index,
sizeof(STD_UnsignedInteger32));
}
//!!!!!!!!!!!!!!!!!!!!!
// CODE DELETED : not usefull for this example
//!!!!!!!!!!!!!!!!!!!!!
}