i'm attempting create sample application utilizing microsoft's winsnmp library create example of trap. see code sample below:
//send trap; lpstr strsrcaddr = "10.12.0.21"; lpstr strdstaddr = "10.2.255.8"; uint32 ndstport = 462; smiint snmppdutype = snmp_pdu_trap; hsnmp_vbl snmpvarbindlist = snmpcreatevbl(snmpsession, null, null); assert(snmpvarbindlist != snmpapi_failure); //copy src address src entity; hsnmp_entity snmpsrcentity = snmpstrtoentity(snmpsession, strsrcaddr); assert(snmpsrcentity != snmpapi_failure); //copy dst address dst entity; hsnmp_entity snmpdstentity = snmpstrtoentity(snmpsession, strdstaddr); assert(snmpdstentity != snmpapi_failure); //assign dst entity trap port; snmpstatus = snmpsetport(snmpdstentity, ndstport); assert(snmpstatus != snmpapi_failure); //create pdu, assigning trap_type; hsnmp_pdu snmppdu = snmpcreatepdu(snmpsession, snmppdutype, null, null, null, snmpvarbindlist); assert(snmppdu != snmpapi_failure); //send msg; smibyte pbytedata[] = "public\0"; smioctets snmpctxoctects = {6, (smilpbyte)pbytedata}; hsnmp_context snmpctxt = snmpstrtocontext(snmpsession, &snmpctxoctects); assert(snmpctxt != snmpapi_failure); ////////////////////////////////// // // create pdu , set data; // ////////////////////////////////// ///// //-- set sysuptime; ///// char poidsysuptimearray[] = "1.3.6.1.2.1.1.3.0\0"; smioid snmpoidsysuptime = {0}; snmpstatus = snmpstrtooid(poidsysuptimearray, &snmpoidsysuptime); assert(snmpstatus != snmpapi_failure); smivalue smivaluesysuptime = {0}; smivaluesysuptime.syntax = snmp_syntax_timeticks; smivaluesysuptime.value.unumber = 40000; //random up-time; snmpstatus = snmpsetvb(snmpvarbindlist, 0, &snmpoidsysuptime, &smivaluesysuptime); assert(snmpstatus != snmpapi_failure); ///// //-- set snmptrapoid; ///// char poidsnmptrapoid[] = "1.3.6.1.6.3.1.1.4.1.0\0"; char poidsnmpoidofenttrap[] = "1.3.6.1.4.1.37086.2.0.1\0"; smioid snmpoidofenttrap = {0}; smioid snmpoidtrapoid = {0}; snmpstatus = snmpstrtooid(poidsnmptrapoid, &snmpoidtrapoid); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpstrtooid(poidsnmpoidofenttrap, &snmpoidofenttrap); assert(snmpstatus != snmpapi_failure); smivalue smivalueenttrap = {0}; smivalueenttrap.syntax = snmp_syntax_oid; smivalueenttrap.value.oid = snmpoidofenttrap; snmpstatus = snmpsetvb(snmpvarbindlist, 0, &snmpoidtrapoid, &smivalueenttrap); assert(snmpstatus != snmpapi_failure); ///// //-- add vb 1.3.6.1.4.1.37086.1.1.0 ///// char poidsnmptrapvalueoid[] = "1.3.6.1.4.1.37086.1.1.0\0"; smioid snmpoidtrapvalueoid = {0}; snmpstatus = snmpstrtooid(poidsnmptrapvalueoid, &snmpoidtrapvalueoid); assert(snmpstatus != snmpapi_failure); smivalue smivaluetrapvalue = {0}; smivaluetrapvalue.syntax = snmp_syntax_int; smivaluetrapvalue.value.snumber = 2; //failure; snmpstatus = snmpsetvb(snmpvarbindlist, 0, &snmpoidtrapvalueoid, &smivaluetrapvalue); assert(snmpstatus != snmpapi_failure); ////////////////////////////////// // // finished pdu creation; // ////////////////////////////////// //attempt send message; snmpstatus = snmpsendmsg(snmpsession, snmpsrcentity, snmpdstentity, snmpctxt, snmppdu); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreepdu(snmppdu); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreevbl(snmpvarbindlist); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreedescriptor(snmp_syntax_oid, (smilpopaque)&snmpoidsysuptime); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreedescriptor(snmp_syntax_oid, (smilpopaque)&snmpoidtrapoid); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreedescriptor(snmp_syntax_oid, (smilpopaque)&smivalueenttrap.value.oid); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreeentity(snmpsrcentity); assert(snmpstatus != snmpapi_failure); snmpstatus = snmpfreeentity(snmpdstentity); assert(snmpstatus != snmpapi_failure);
i can see trap hitting wire , being received unfortunately snmp manager not notifying me of trap. have feeling problem formation of trap side on not problem manager (snmpc manager)?
this custom mib have created dummy oid:
marina-mib definitions ::= begin imports enterprises rfc1155-smi object-type, notification-type rfc-1212 ; epilogue object identifier ::= {enterprises 37086} marina object identifier ::= {epilogue 1} marinanotices object identifier ::= {epilogue 2} marinastatus object-type syntax integer { ok (1), failure (2) } max-access accessible-for-notify status current description "the status of marina." ::= {marina 1} marinastatusnotification notification-type objects { marinastatus } status current description "this variable notifies listeners of status of marina." ::= {marinanotices 1} end
in addition, have link wireshark dump of capture of trap.
snmpc manager allow me send dummy traps using little tool; however, these traps snmpv2 , winsnmp using v1, difficult me compare. suggestions appreciated.
as lex li proposed, i'm adding answer:
the traps should sent port no 162
Comments
Post a Comment