I made a trap receiver application. I just only modified the
snmptrapd_handler in the next way:
int print_handler( netsnmp_pdu *pdu,
netsnmp_transport *transport,
netsnmp_trapd_handler *handler){
int iii= ems_flush_traps(pdu,transport);
return NETSNMPTRAPD_HANDLER_OK;
}
int ems_flush_traps(netsnmp_pdu *pdu, netsnmp_transport *transport) {
display(pdu,transport);
return 0;}
int display(netsnmp_pdu *pdu, netsnmp_transport *transport) {
oid OID1[]={1,3,6,1,4,1,24024,200,200,1};
oid OID2[]={1,3,6,1,4,1,24024,200,200,2};
oid OID4[]={1,3,6,1,4,1,24024,200,200,4};
netsnmp_variable_list *vars;
char alarmaName[40];
char dateIn[40];
//long id[40];
long idSeverity[40];
char strIdSeverity[2];
char strTime[20];
char clean[] = "";
netsnmp_pdu * internal_pdu;
internal_pdu = snmp_clone_pdu(pdu);
int ii=0;
char stringBuffer[20];
for (vars = internal_pdu->variables; vars != NULL; vars =
vars->next_variable){
// Alarm name
if(memcmp(OID1, vars->name_loc, sizeof(OID1))==0){
memcpy (alarmaName, vars->val.string,
strlen(vars->val.string)+1);
printf("alarm Name: %s\n",alarmaName);
printf("alarm Name: %s\n",vars->val.string);
//memcpy ( vars->val.string, clean, strlen(clean)+1 );
//vars->val.string=NULL;
}
if(memcmp(OID2, vars->name_loc, sizeof(OID2))==0){
memcpy (idSeverity, vars->val.integer,
sizeof(vars->val.integer) );
sprintf(strIdSeverity, "%lu", idSeverity[0]);
printf("Severity: %s\n",strIdSeverity);
printf("Severity: %lu\n",vars->val.integer[0]);
}
if(memcmp(OID4, vars->name_loc, sizeof(OID4))==0){
memcpy ( dateIn , vars->val.string,
strlen(vars->val.string)+1 );
printf("Date: %s\n",dateIn);
printf("Date: %s\n",vars->val.string);
//memcpy ( vars->val.string, clean, strlen(clean)+1 );
//vars->val.string=NULL;
}
//strcpy(vars->val.string, "");
}
free(vars);
snmp_free_pdu( internal_pdu );
return 0;
}
with the next commands line i executed several times the program:
$ sudo snmptrapd -f -Le -F "%v\n"
$ sudo snmptrap -v 2c -c public 192.168.0.40 ""
1.3.6.1.4.1.24024.200.200.1 1.3.6.1.4.1.24024.200.200.1 s latenciawan
1.3.6.1.4.1.24024.200.200.2 i 2 1.3.6.1.4.1.24024.200.200.3 s MINOR
1.3.6.1.4.1.24024.200.200.4 s "2013/02/18 15:36:00"
the result was:
alarm Name: latenciawan
alarm Name: latenciawanSeverity: 2Severity: 2Date: 2013/02/18
15:36:00Date: 2013/02/18 15:36:00
and after several executions i have some times the wrong result:
alarm Name: latenciawan15:36:00
alarm Name: latenciawan15:36:00Severity: 2Severity: 2Date: 2013/02/18
15:36:00Date: 2013/02/18 15:36:00
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders