snmpUserGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All NX devices

Firmware version:

1.52.00


This function will read out a user from the list of USM users on the manager, previously set by the snmpUserSet function.

The list contains the USM user profiles of the users that are allowed to send traps to the manager.

 

Input:

Index : SINT (1..25)

The index of the user.

 

Output:

User : snmpUser

The information about the user. See snmpUser.

 

Returns: INT

1

- Success.

0

- This function is not supported.

-2

- Illegal index.

 

Declaration

FUNCTION snmpUserGet : INT;
VAR_INPUT
  index : MANDATORY SINT;
  user  : ACCESS snmpUser;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  user     : snmpUser;
  iface    : SINT := 2;
END_VAR;
 
FUNCTION show_user
VAR_INPUT
  index       : SINT;
END_VAR;
VAR
  str         : STRING;
  rc          : INT;
END_VAR;
 
  // Get user
  rc := snmpUserGet(index := index, user := user);
  IF rc < 1 THEN
    DebugFmt(message := "  snmpUserGet=\1", v1 := rc);
    RETURN;
  END_IF;
 
  // Show
  DebugMsg(message := "--------------------------------------------------");
  DebugFmt(message := "User \1:", v1 := index);
  IF strLen(str := user.username) = 0 THEN
    DebugMsg(message := "  <EMPTY>");
  ELSE
    DebugMsg(message := "  Name               = " + user.username);
    DebugMsg(message := "  Password           = " + user.password);
    DebugMsg(message := "  Encrypt key        = " + user.cryptkey);
    DebugMsg(message := "  Engine ID          = " + user.engineid);
    CASE user.level OF
        0: DebugMsg(message := "  Level              = None");
        1: DebugMsg(message := "  Level              = Authenticate");
        2: DebugMsg(message := "  Level              = Encrypt");
    END_CASE;
    IF user.authentication = _SNMP_USM_MD5 THEN
        DebugMsg(message := "  Authentication     = MD5");
    ELSE
        DebugMsg(message := "  Authentication     = SHA");
    END_IF;
    IF user.encryption = _SNMP_USM_AES THEN
        DebugMsg(message := "  Encryption         = AES");
    ELSE
        DebugMsg(message := "  Encryption         = DES");
    END_IF;
  END_IF;
 
END_FUNCTION;
 
PROGRAM example;
VAR
  i        : SINT;
  rc       : INT;
  handle   : SYSHANDLE;
END_VAR;
 
  // Iterate Users
  FOR i := 1 TO 10 DO
    show_user(index := i);
  END_FOR;
 
  // Build user
  user.username        := "Administrator";
  user.password        := "Pass phrase";
  user.cryptkey        := "Pass phrase";
  user.engineid        := "8000000001020304";
  user.level           := _SNMP_SEC_ENC;
  user.authentication  := _SNMP_USM_MD5;
  user.encryption      := _SNMP_USM_AES;
 
  // Set user
  rc := snmpUserSet(index := 1, user := user);
  IF rc < 1 THEN
    DebugFmt(message := "snmpUserSet=\1", v1 := rc);
  END_IF;
 
  // Open net interface.
  rc := netOpen(iface := iface);
  DebugFmt(Message := "netOpen (rc=\1)", v1 := rc);
  WHILE NOT netConnected(iface := iface) DO
    Sleep(Delay := 2000);
  END_WHILE;
 
  // Start to listen for traps
  rc := snmpStartListen(
                        handle    := handle,
                        community := "public"
                       );
  IF rc < 1 THEN
    DebugFmt(message := "snmpStartListen=\1", v1 := rc);
  END_IF;
  rc := snmpRegisterTrap(oid := "1.3.6.1.4.1.6101.1.8.8.2.6");
  IF rc < 1 THEN
    DebugFmt(message := "snmpRegisterTrap=\1", v1 := rc);
  END_IF;
 
BEGIN
END;
END_PROGRAM;