Version: 4.0.0.0
Create custom SNMP Manager, Trap and Agent applications for monitoring and controlling network devices.

Using PowerSNMP for ActiveX Pt 2: Creating a simple Manager in VB.

 

Skill level:   Beginner
Software required:   · Visual Basic 6
· powerSNMP for ActiveX

Overview

As demonstrated in Part 1 of this tutorial, the PowerSNMP product can be used to quickly create simple SNMP agents. In Part 2, a Manager application is created for requesting the value of an agent's sysDescr variable.


Step 1

  1. Download and install powerSNMP for ActiveX.

  2. Create a new project in Visual Basic.
    • Start Visual Basic
    • From the opening dialog, select Standard Exe and click OK

  3. Add an SNMP Manager Control to the form.
    • Right-click the Toolbox and select Components
    • Find the SNMP Manager control; select and click OK

  4. Drag an instance of the SNMP Manager Control onto the form.

 


Step 2

Now add the code necessary to initialize and start the Manager.

  1. Add a Command Button to the form.

  2. Access the button's OnClick event by double-clicking the button.

  3. Place the following code within the OnClick event of the button added above.

Private Sub Command1_Click()
   Dim Variable As New SnmpVariable

   ' Default port for SNMP Managers is 162
   Manager1.Open 162

   'The OID for sysDescr
   Variable.Oid = "1.3.6.1.2.1.1.1.0"

   'Clear the Variables property - good practice
   Manager1.Message.Reset
 
   'Specify that you want an SNMP Get request
   Manager1.Message.Type = snmpGet1

   'Add the Variables to the SNMP Message
   Manager1.Message.Variables.Add Variable

   'AgentPort defaults to 161, but important to set it anyway
   Manager1.AgentPort = 161
   Manager1.AgentName = "localhost"

   'Send the Message
   Manager1.Send
End Sub
           

 


Step 3

Now add code to handle the Manager Response event.

  1. Add a ListBox to the form.

  2. Select the Manager Response event using the drop-down windows at the top of the code editor.

  3. Add the code below to the event.

Private Sub Manager1_Response()
  Dim Variable As SnmpVariable

  'Use intrinsic error handling
  On Error GoTo OnError

  'Specify the Agent responding
  List1.AddItem "Message from " + Manager1.AgentName

  'Check to see if a Get/Set completed successfully
  If Manager1.Message.Exception = snmpOk Then
     'Extract all variables
     For Each Variable In Manager1.Message.Variables
       'Display variables on a ListBox
       List1.AddItem Variable.Value
     Next
  Else
      'Identifies which variable is at fault
      '(Normally bad practice to use a MessageBox in an event, but
      'OK for this simple example)
      MsgBox "Error in variable: " & Manager1.Message.ExceptionIndex
  End If
Exit Sub

OnError:
    MsgBox "Error with Response: " & Err.Description
End Sub
           

 


Step 4

Compile and run the application. Click the button to start the Manager and send a message to your Agent (Be sure the Agent you created in Part 1 of this tutorial is running). You should see a response in the ListBox.