This project is read-only.
This allows for loading and persisting entities using the SNMP protocol. It also allows for embedding (or rather extract and control) the net-snmp agent. This is currently used for unit testing.

Example usage for embedding net-snmp in application (fires up as a separate process but controlled by your application lifetime).

static void Main()
   // This will extract snmpd.exe (arch *sensitive*) into ServerPath
  using(var embeddedServer = 
             new EmbeddableSnmpAgent 
               {ServerPath = Path.Combine(Path.GetTempPath(), "embeddednetsnmp")})
    // Use the snmp communication here

  } // process snmpd.exe gets shutdown here

Loading entities over the snmp protocol, in this example using the built in windows snmp agent to load active windows services.

EntityPersistorFactory factory = Factory.GetEntityFactory();

using (EntitySession session = factory.OpenSession())
  foreach (WindowsService service in from service in session.Load<WindowsService>()
                    where service.OpertatingState == OperatingStateTypes.Active
                    orderby service.Name
                    select service)

Where the WindowsService entity looks like this.
[Entity(BaseOid = "")]
public class WindowsService
  [Property(SubOid = 1)]
  public string Name { get; set; }

  [Property(SubOid = 2)]
  public InstallStateTypes InstalledState { get; set; }

  [Property(SubOid = 3)]
  public OperatingStateTypes OpertatingState { get; set; }

  [Property(SubOid = 4)]
  public UninstallTypes CanBeUninstalled { get; set; }

  [Property(SubOid = 5)]
  public PausedTypes CanBePaused { get; set; }

It now now wery simple to use more comple operations using linq for entities (we're currently investigating creatinga fully SNMP linq provider to do optimizations on the SNMP protocol layer). This example do join and projection in a one liner...
public void DisplayIpEntryForInterfaces()
  EntityPersistorFactory factory = Factory.GetEntityFactory();

  using (EntitySession session = factory.OpenSession())
     var query = from conn in session.Load<InterfaceIpAddress>()
        join intf in session.Load<Interface>() on conn.InterfaceIndex equals intf.Index
        orderby intf.Index
        select new { intf.Index, intf.Description, conn.Address, NetMask = conn.Netmask };

     foreach (var entry in query)
       Console.WriteLine("[{0}] {1}/{2} {3}", 

It is also possible to create type-converter (if the built-in are not sufficient) to provide conversion between snmp textual conventions to Net types. Some are implicit like IpAddress or DateTime etc. But cusom type converters can be decorated on the properties to do the conversion back and from snmp.

This is a example where typeconverters are used in order to convert a SNMP PhysicalAddress TC into a .net string
[Entity(BaseOid = "", 
          Description = "This class encapsulates the ipNetToMediaTable")]
public class NetMedia
    [Property(SubOid = 1, Access = PropertyAccess.ReadWrite)]
    public int Interface { get; set; }

    [Property(SubOid = 3, Access = PropertyAccess.ReadWrite)]
    public IPAddress Address { get; set; }

    [Property(SubOid = 2, 
                  Access = PropertyAccess.ReadWrite, 
                  Type = typeof(PhysicalMedia))]
    public string PhysicalAddress { get; set; }

    [Property(SubOid = 4, Access = PropertyAccess.ReadWrite)]
    public MediaType Type { get; set; }

Last edited Aug 17, 2012 at 7:53 AM by solo95, version 8


No comments yet.