snmp自动发trap
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.notify.conf 17838 2009-11-25 20:35:23Z magfr $
*/
#include
#include
#include
#include
#include "fm200_notification.h"
extern const oid snmptrap_oid[];
extern const size_t snmptrap_oid_len;
int content = 3;
int send_XXX_trap( int i_num_index )
{
netsnmp_variable_list *var_list = NULL;
oid XXX_oid[] = { 1,3,6,1,4,1,11161,2,0,26 };
oid XXXA_oid[] = { 1,3,6,1,4,1,11161,2,5,1,2,1,2,0 /* insert index here */ };
size_t XXXA_oid_len = OID_LENGTH(XXXA_oid);
XXXA_oid[XXXA_oid_len - 1] = i_num_index + 1;
/*
* Set the snmpTrapOid.0 value
*/
snmp_varlist_add_variable(&var_list,
snmptrap_oid, snmptrap_oid_len,
ASN_OBJECT_ID,
XXX_oid, sizeof(XXX_oid));
/*
* Add any objects from the trap definition
*/
snmp_varlist_add_variable(&var_list,
XXXA_oid, OID_LENGTH(XXXA_oid),
ASN_INTEGER,
/* Set an appropriate value for XXXA*/
&content, sizeof(int));
/*
* Add any extra (optional) objects here
*/
/*
* Send the trap to the list of configured destinations
* and clean up
*/
send_v2trap( var_list );
snmp_free_varbind( var_list );
return SNMP_ERR_NOERROR;
}
int send_YYY_trap(int i_num_index)
{
netsnmp_variable_list *var_list = NULL;
oid YYY_oid[] = { 1,3,6,1,4,1,11161,2,0,27 };
oid YYYA_oid[] = { 1,3,6,1,4,1,11161,2,5,1,2,1,3,0 /* insert index here */ };
size_t YYYA_oid_len = OID_LENGTH(YYYA_oid);
YYYA_oid[YYYA_oid_len - 1] = i_num_index + 1;
/*
* Set the snmpTrapOid.0 value
*/
snmp_varlist_add_variable(&var_list,
snmptrap_oid, snmptrap_oid_len,
ASN_OBJECT_ID,
YYY_oid, sizeof(YYY_oid));
/*
* Add any objects from the trap definition
*/
snmp_varlist_add_variable(&var_list,
YYYA_oid, OID_LENGTH(YYYA_oid),
ASN_INTEGER,
/* Set an appropriate value for YYYA*/
&content, sizeof(int));
/*
* Add any extra (optional) objects here
*/
/*
* Send the trap to the list of configured destinations
* and clean up
*/
send_v2trap( var_list );
snmp_free_varbind( var_list );
return SNMP_ERR_NOERROR;
}
然后在初始化init_XXX_notification()
最后要把snmpd.conf的文件配置好,向那发trap,就写好改IP,实际情况还是要根据项目来定发trap的条件。