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

SNMP Trap Catcher Code Example

The following example demonstrates an SNMP manager in a Windows Forms environment. The manager receives and handles traps, notifications and inform requests.

< Back to all samples for PowerSNMP for .NET

private void button1_Click(object sender, EventArgs e)
{
    //Start listening for traps, notifications and informs
    manager1.Start(manager1_MessageReceived, null);
}

private void manager1_MessageReceived(Manager manager, MessageBase message, object state)
{
    //Marshal message to the UI thread using the Message event
    if (message is TrapMessage)
        manager.Marshal(new MessageBase[] { message }, "trap"null);
    else if (message is NotificationMessage)
        manager.Marshal(new MessageBase[] { message }, "notification"null);
    else if (message is InformMessage)
    {
        manager.Marshal(new MessageBase[] { message }, "inform"null);

        //Send response to inform message origin
        manager.Send(new ResponseMessage(message as InformMessage), message.Origin);
    }
}

private void manager1_Message(object sender, MessageEventArgs e)
{
    //Update interface according to message type received
    switch (e.Message)
    {
        case "trap":
            TrapMessage trap = e.Messages[0] as TrapMessage;
            label1.Text = "Trap received with Enterprise(" + trap.Enterprise +
                "), Generic Type (" + trap.GenericTrap.ToString() + "), Specific Type(" +
                trap.SpecificTrap.ToString() + ")";
            break;
        case "notification":
            NotificationMessage notification = e.Messages[0] as NotificationMessage;
            label1.Text = "Notification received with OID (" + notification.Oid + ")";
            break;
        case "inform":
            InformMessage inform = e.Messages[0] as InformMessage;
            label1.Text = "Inform received with " + inform.Variables.Count.ToString() +
                " variable(s).";
            break;
    }
}