0

I'm attempting to monitor multiple SNMP agents (timeticks) with SnmpSharpNet across separate networks. The code below works with a single IP address, but when I try and connect to a second IP address the code fails, I'm trying to run this asynchronously but it appears that SnmpSharpNet won't allow me to receive data from more than one agent.

Is this the right way to approach this problem? Is there a better alternative to SmnpSharpNet?

community = new OctetString("public");
// Define agent parameters class
param = new AgentParameters(community);
// Set SNMP version to 1 (or 2)
param.Version = SnmpVersion.Ver1;

for (int i = 0; i < sendsqldatalist.Count(); i++)
{
    agent = new IpAddress(sendsqldatalist[i].ip);
    target = new UdpTarget((IPAddress)agent, 161, 2000, 1);

    // Make SNMP request        
    resultlist.Add(result = (SnmpV1Packet)target.Request(pdu, param));

    // If result is null then agent didn't reply or we couldn't parse the reply.r
    if (resultlist[i] != null)
    {
        // ErrorStatus other then 0 is an error returned by 
        // the Agent - see SnmpConstants for error definitions
        if (resultlist[i].Pdu.ErrorStatus != 0)
        {
            Console.WriteLine("error on - " + sendsqldatalist[i].oid + "    " + sendsqldatalist[i].ip);
            // agent reported an error with the request
            //- Error status found here http://www.docs.snmpsharpnet.com/docs-0-9-1/
            MessageBox.Show("Error in SNMP reply from " + target.Address.ToString() + Environment.NewLine + "Error status " + result.Pdu.ErrorStatus.GetType() + Environment.NewLine + "Error Index " + result.Pdu.ErrorIndex.ToString(), "WARNING!");
        }
        else
        {
            Console.WriteLine("ConnectSNMP() CONNECTED - " + sendsqldatalist[i].oid + "  -  " + sendsqldatalist[i].ip);                           
        }                    
    }
}

Thanks in advance!

clomas
  • 63
  • 1
  • 9

0 Answers0