Notification trap type problem

Klemen Sladic <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAN6eUaEnhTk1vU1phv887kZzanKGik8=R2maynuRbwct7diUyQ@mail.gmail.com>
Hi.

I have a question about notification (trap) type since I am getting
"Wrong Type (should be INTEGER)".
For example, let's say this is in my MIB:

Object definition:
myTrigger OBJECT-TYPE
    SYNTAX      INTEGER { down1(10), up1(11), down2(20), up2(21) }
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION  "Some desc."
    ::= { mySystem 39 }

Trap definition:
myTrap NOTIFICATION-TYPE
   OBJECTS { myTrigger }
   STATUS  current
   DESCRIPTION "Some desc."
   ::= { myTraps 9 }

What I want is to do snmpset of myTrigger as integer, but get a trap as a
string. Inside my agent's myTrigger handler, I take the integer and create
a string, like "Trap triggered by %d.":

snmptrapd[13583]: 2019-12-02 13:39:29 <UNKNOWN> [UDP:
[192.168.0.1]:34138->[192.168.0.2]:162]:#012DISMAN-EVENT-MIB::sysUpTimeInstance
= Timeticks: (884381) 2:27:23.81#011SNMPv2-MIB::snmpTrapOID.0 = OID:
MY-MIB::myTrap#011MY-MIB::myTrigger.0 = Wrong Type (should be INTEGER):
STRING: "Trap triggered by 10."

Is that because myTrap output is string not integer and thus of different
type as myTrigger?

Here is myTrigger handler from the agent:

int myTrigger(netsnmp_mib_handler          *handler,
              netsnmp_handler_registration *reginfo,
              netsnmp_agent_request_info   *reqinfo,
              netsnmp_request_info         *requests)
{
   int  ival = *(requests->requestvb->val.integer); // integer from snmpset
   char msg[64] = {0}; // resulting string

   switch (reqinfo->mode) {
      case MODE_SET_ACTION:
            switch (ival)
            {
               case 10: strncpy(msg, " Trap triggered by 10", 64 - 1);
break;
               case 11: strncpy(msg, " Trap triggered by 11", 64 - 1);
break;
               case 20: strncpy(msg, " Trap triggered by 20", 64 - 1);
break;
               case 21: strncpy(msg, " Trap triggered by 21", 64 - 1);
break;
               default: strncpy(msg, "Unknown port state.", 64 - 1); break;
            }
            sendTrap_myTrap(msg); // this function will wend the trap
         break;
      default:
         break;
   }

   return SNMP_ERR_NOERROR;
}

Thank you very much for your help.

RegK

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.