Re: Re: problem about sending V2 trap
liuying <liuying <at> sgchip.com>
2011-05-03 07:34:28 GMT
>And what is the (full) code of this routine?
int
write_exampletrap2(int action,
u_char * var_val,
u_char var_val_type,
size_t var_val_len,
u_char * statP,oid * name, size_t name_len)
{
long intval;
oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; /* snmpTrapOID.0 */
oid demo_trap[] = { 1, 3, 6, 1, 4, 1, 43571, 6,2,0 }; /*demo-trap */
oid pon_oid[]={ 1, 3, 6, 1, 4, 1, 43571, 2, 1,1,4};
oid onu_oid[]={1,3,6,1,4,1,43571,3,2,1,1,34};
oid onu485_oid[]={1,3,6,1,4,1,43571,3,4,1,1,134};
printdebug(pon_oid,sizeof(pon_oid) / sizeof(oid));
static netsnmp_variable_list var_trap;
static netsnmp_variable_list var_str;
static netsnmp_variable_list var_pon;
static netsnmp_variable_list var_onu;
static netsnmp_variable_list var_onu485;
static sendtrap_list var_default;
DEBUGMSGTL(("example", "write_exampletrap2 entered: action=%d\n",action));
switch (action) {
case RESERVE1:
/*
* The only acceptable value is the integer 1
*/
if (var_val_type != ASN_INTEGER) {
DEBUGMSGTL(("example", "%x not integer type", var_val_type));
return SNMP_ERR_WRONGTYPE;
}
if (var_val_len > sizeof(long)) {
DEBUGMSGTL(("example", "wrong length %x", var_val_len));
return SNMP_ERR_WRONGLENGTH;
}
intval = *((long *) var_val);
if (intval != 1) {
DEBUGMSGTL(("example", "wrong value %x", intval));
return SNMP_ERR_WRONGVALUE;
}
break;
case RESERVE2:
/*
* No resources are required....
*/
break;
case FREE:
/*
* ... so no resources need be freed
*/
break;
case ACTION:
/*
* Having triggered the sending of a trap,
* it would be impossible to revoke this,
* so we can't actually invoke the action here.
*/
break;
case UNDO:
/*
* We haven't done anything yet,
* so there's nothing to undo
*/
break;
case COMMIT:
strcpy(var_default.trap_str,"onureg");
var_default.trap_str_len = sizeof(var_default.trap_str);
// memset(var_default.sgcc_trap_oid,0,sizeof(var_default.sgcc_trap_oid));
memcpy(var_default.pon_oid,pon_oid,sizeof(pon_oid));
memcpy(var_default.onu_oid,onu_oid,sizeof(onu_oid));
memcpy(var_default.onu485_oid,onu485_oid,sizeof(onu485_oid));
var_default.pon_oid_len = sizeof(var_default.pon_oid);
var_default.onu_oid_len = sizeof(var_default.onu_oid);
var_default.onu485_oid_len = sizeof(var_default.onu485_oid);
var_default.is485 = 1;
var_default.traptype = 8;
printf("in var objects\n");
var_trap.next_variable = &var_str; /* next variable */
var_trap.name = objid_snmptrap; /* snmpTrapOID.0 */
var_trap.name_length = sizeof(objid_snmptrap) / sizeof(oid); /* number of sub-ids */
var_trap.type = ASN_OBJECT_ID;
var_trap.val.objid = demo_trap; /* demo-trap objid */
var_trap.val_len = sizeof(demo_trap); /* length in bytes (not number of subids!) */
/*
* additional objects
*/
var_str.next_variable = &var_pon; /* next variable*/
var_str.type = ASN_INTEGER; /* type of variable */
var_str.val.integer = &var_default.traptype; /* value */
var_str.val_len = sizeof(var_default.traptype);
var_pon.next_variable = &var_onu; /* next variable */
var_pon.name = var_default.pon_oid;
var_pon.name_length = sizeof(var_default.pon_oid)/ sizeof(oid); /* number of sub-ids */
var_pon.type = ASN_OCTET_STR; /* type of variable */
var_pon.val.string = "PONoid"; /* value */
var_pon.val_len = sizeof("PONoid");
if(var_default.is485==1)
{
var_onu.next_variable = &var_onu485;
}
else
{
var_onu.next_variable = NULL;
}
var_onu.name = var_default.onu_oid;
var_onu.name_length = sizeof(var_default.onu_oid)/ sizeof(oid); /* number of sub-ids */
var_onu.type = ASN_OCTET_STR; /* type of variable */
var_onu.val.string = "ONUoid"; /* value */
var_onu.val_len = sizeof("ONUoid");
var_onu485.next_variable = NULL; /* No more variables after this one */
var_onu485.name = var_default.onu485_oid;
var_onu485.name_length = sizeof(var_default.onu485_oid) / sizeof(oid);/* number of sub-ids */
var_onu485.type = ASN_OCTET_STR; /* type of variable */
var_onu485.val.string = "ONU485oid"; /* value */
var_onu485.val_len = sizeof("ONU485oid");
DEBUGMSGTL(("example", "write_exampletrap2 sending the v2 trap\n"));
send_v2trap(&var_trap);
DEBUGMSGTL(("example", "write_exampletrap2 v2 trap sent\n"));
break;
}
return SNMP_ERR_NOERROR;
}
>What is the MIB definition of the trap that you are trying to send?
>
-- 1.3.6.1.4.1.43571.6
trapall OBJECT IDENTIFIER ::= { sgcc 6 }
-- 1.3.6.1.4.1.43571.6.1
trigger OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Description."
::= { trapall 1 }
-- 1.3.6.1.4.1.43571.6.2
onutrap NOTIFICATION-TYPE
OBJECTS { trigger }
STATUS current
DESCRIPTION
"Description."
::= { trapall 2 }
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users <at> lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users