c - NET-SNMP agent trap v3 configuration -


im trying implement agent trap v3 sender using net-snmp.

currently status im able start snmpd , daemon sending coldstart trap host defined in snmpd.conf

my snmpd.conf:

createuser myuser sha "12345678" aes  rouser myuser auth   trapsess -v 3 -u myuser -n contextname -l authpriv -a sha -a 12345678 -x aes -        x 12345678 host_ip:162   group groupv3            usm      myuser  ##          incl/excl subtree                         mask view    included  .1                               80  access groupv3         ""              auth      exact                        

var/net-snmp/snmpd.conf contain hash user, if im using snmptrap command in linux can see trap recived host wireshark sniffer.

but im unable send traps code (im restricted c, embedded system). im using send_v2trap() api, , when im defined vars list nothing sent out. im not sure need define, need open session or snmpd.conf file enough? need define send trap via code?

i tried use examples provided no luck

this 1 of them:

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;      /*      * these variales used when send trap       */     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, 2021, 13, 990 };  /*demo-trap */     oid             example_string_oid[] =         { 1, 3, 6, 1, 4, 1, 2021, 254, 1, 0 };     static netsnmp_variable_list var_trap;     static netsnmp_variable_list var_obj;      debugmsgtl(("example", "write_exampletrap2 entered: action=%d\n",                 action));     switch (action) {     case reserve1:         /*          *  acceptable value 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 %" netsnmp_priz "u",                         var_val_len));             return snmp_err_wronglength;         }          intval = *((long *) var_val);         if (intval != 1) {             debugmsgtl(("example", "wrong value %lx", intval));             return snmp_err_wrongvalue;         }         break;      case reserve2:         /*          * no resources required....           */         break;      case free:         /*          * ... no resources need freed           */         break;      case action:         /*          *  having triggered sending of trap,          *   impossible revoke this,          *   can't invoke action here.          */         break;      case undo:         /*          * haven't done yet,          * there's nothing undo           */         break;      case commit:         /*          *  else worked, it's safe          *   trigger trap.          *  note *only* acceptable since          *   trap sending routines "failsafe".          *  (in fact, can fail, return no          *   indication of this, next best thing!)          */          /*          * trap definition objects           */          var_trap.next_variable = &var_obj;      /* 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_obj.next_variable = null;   /* no more variables after 1 */         var_obj.name = example_string_oid;         var_obj.name_length = sizeof(example_string_oid) / sizeof(oid); /* number of sub-ids */         var_obj.type = asn_octet_str;   /* type of variable */         var_obj.val.string = (unsigned char *) example_str;       /* value */         var_obj.val_len = strlen(example_str);         debugmsgtl(("example", "write_exampletrap2 sending v2 trap\n"));         send_v2trap(&var_trap);         debugmsgtl(("example", "write_exampletrap2 v2 trap sent\n"));          break;      }     return snmp_err_noerror; } 

any or example appreciated

thanks in advance


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -