none
Accessing SNMP data on remote appliances RRS feed

  • Question

  • I am trying to use System.Management to read the RFC1213 table from a remote appliance. I've done this in the past with COM-Interop and some samples found online, but there is a fair amount of overhead to pulling in COM and I feel like I'm very close and just missing something with System.Management. Here is a code sample:

     

    public static void Main( string[ ] args )

    {

     

    LookupDevice( "public", "192.168.105.60" );

    }

     

    static void LookupDevice( string targetCommunity, string targetDevice )

    {

     

    ManagementScope scope;

     

    ManagementPath mpath;

     

    ManagementClass mc;

     

    ManagementNamedValueCollection queryParameters;

     

    EnumerationOptions queryOptions;

     

    scope = new ManagementScope( "root\\snmp\\localhost" );

     

    mpath = new ManagementPath( "SNMP_RFC1213_MIB_ifTable" );

     

    queryParameters = new ManagementNamedValueCollection( );

     

    queryParameters.Add( "AgentAddress", targetDevice );

     

    queryParameters.Add( "AgentReadCommunityName", targetCommunity );

     

    queryOptions = new EnumerationOptions( );

     

    queryOptions.Context = queryParameters;

     

    using ( mc = new ManagementClass( scope, mpath, null ) )

    {

     

    foreach ( ManagementObject mo in mc.GetInstances( queryOptions ) )

    {

     

    Console.WriteLine( "ifIndex: {0}", mo[ "ifIndex" ] );

     

    Console.WriteLine( "ifDescr: {0}", mo[ "ifDescr" ] );

    }

    }

    }

     

    I get a "not found" ManagementException when it tries to get the instances in the GetInstances() call. Help!

     

    Thanks

    --C.J.

    Tuesday, November 16, 2010 10:20 PM

All replies

  • Can you provide more detail information about the exception?
    Thursday, November 18, 2010 1:42 PM
  • It is a System.Management exception with "Not Found". That's all the detail you get from WMI. It indicates to me that the Query is not using the AgentAddress, etc. to talk to the remote system at all.
    Friday, November 19, 2010 6:30 PM
  • Hi Bone,

    Thank you for your question. We're doing research on this issue. It might take some time before we get back to you.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, November 23, 2010 3:05 AM
  • Hi,

    1)      Have you set up the WMI environment for SNMP provider as given in http://msdn.microsoft.com/en-us/library/aa393621(VS.85).aspx

    2)      Are you able to query the class using wbemTest?

     

     

    Your issue falls into a category that we are not able to resolve using the forums. There are

    various support options such as advisory and per issue. Please visit the below link to see the

    various paid support options that are available to better meet your needs.

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Alliance and Premier VSIP membership includes a complimentary MSDN subscription, which includes 4

    professional support incidents. These can be used to initialize a support request with

    Microsoft's Customer Support Services. Some versions of Visual Studio include a number of free

    support incidents as well. See the "Technical Support Incidents" topic for details.


    bill boyce
    Tuesday, December 7, 2010 10:17 PM
    Moderator