snmpGetNextVar (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All NX devices

Firmware version:

1.50.00


Get the next SNMP trap variable associated with the last received event. See snmpWaitEvent.

Call this function as many times as snmpWaitEvent reported that there was trap variables associated with the event to get all variables.

 

Input:

None.

 

Output:

Data : snmpVariable

The received value contained in a general structure. See snmpVariable.

 

Returns: INT

1

- Data available

0

- This function is not supported.

-2

- Invalid parameter

-9

- Invalid variable type.

-11

- No more data

 

Declaration

FUNCTION snmpGetNextVar : INT;
VAR_INPUT
  Data   : ACCESS snmpVariable;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
THREAD_BLOCK snmpMonitor;
VAR
  count : INT;
  oid   : STRING;
  rc    : INT;
  val   : snmpVariable;
  str   : STRING;
END_VAR;
 
WHILE TRUE DO
  rc := snmpWaitEvent(timeout := -1, oid := oid, vars := count);
  IF rc = 1 OR rc = -5 THEN
    DebugMsg(message := "Trap [" + oid + "] received");
    IF rc = -5 THEN
        DebugMsg(message := "(Trap events lost)");
        rc := 1;
    END_IF;
    DebugFmt(message := "Variables: \1", v1 := count);
    IF count > 0 THEN
        // Iterate variables
        WHILE rc = 1 DO
          rc := snmpGetNextVar(data := val);
          IF rc = 1 THEN
              // Build output
              str := "[" + val.oid + "] = ";
              CASE val.type OF
                1: str := str + dintToStr(v := val.time_value);
                2: str := str + dintToStr(v := val.int_value);
                3: str := str + dintToStr(v := val.uint_value);
                4: str := str + "[" + val.str_value + "]";
                5: str := str + "[" + val.hex_value + "]";
                6: str := str + "[" + val.oid_value + "]";
                7: str := str + "[" + val.ip_value + "]";
                8: str := str + floatToStr(v := val.float_value);
                9: str := str + doubleToStr(v := val.double_value);
              ELSE
                str := str + "Unknown variable type (" + intToStr(v := val.type) + ")";
              END_CASE;
          END_IF;
        END_WHILE;
        IF rc < 1 AND rc <> -11 THEN
          DebugFmt(message := "snmpGetNextVar=\1", v1 := rc);
        END_IF;
    END_IF;
  ELSE
    DebugFmt(message := "snmpWaitEvent=\1", v1 := rc);
  END_IF;
END_WHILE;
END_THREAD_BLOCK;
 
PROGRAM example;
VAR
  mon      : snmpMonitor;
  handle   : SYSHANDLE;
  iface    : SINT := 2;
  rc       : INT;
END_VAR;
 
  // Initialize network
  rc := netOpen(iface := iface);
  DebugFmt(message := "netOpen (rc=\1)", v1 := rc);
  WHILE NOT netConnected(iface := iface) DO
    Sleep(Delay := 2000);
  END_WHILE;
 
  // Initialize SNMP
  rc := snmpStartListen(
                        handle    := handle,
                        community := "public",
                        port      := 162
                       );
  DebugFmt(message := "snmpStartListen = \1", v1 := rc);
  rc := snmpRegisterTrap(oid := "1.3.6.1.4.1.6101.1.8.8.2.6");
  DebugFmt(message := "snmpRegisterTrap = \1", v1 := rc);
  mon();
 
BEGIN
END;
END_PROGRAM;