Arnold Petrona

Arnold Petrona

  • NA
  • 159
  • 0

Class Issue

Jul 21 2008 9:05 PM
Good Afternoon

I have a question about Class. I'm new in it but I understood that with class the main Form program will be easier to work with.  I'm working on a SNMP project and the have a lot of objects but all need to use this SNMP query like this :

        //create snmp session
SnmpSession s1 = new SnmpSession();

//create snmp pdu
SnmpPdu pdu = new SnmpPdu();
//Specify the Pdu type
pdu.PduType = EnumPduType.GetPdu;
//Set the community string
pdu.Community = "public";
pdu.Version = SnmpVersion.Version1;

//creat response pdu
SnmpPdu response = null;

// Try to retrieve snmp record
try
{
// Add snmp variable
SnmpVariable var = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.1.5.0");
pdu.AddRequestVariables(var);
// Synchronized request snmp SyncRequest(hostip, port, pdu)
response = s1.SyncRequest("127.0.0.1", 161, pdu);
}
catch (Exception ex)
{
System.Console.Error.WriteLine("Sending PDU: " + ex.Message);
System.Environment.Exit(1);
}

// Display the result
try
{
if(response.ErrorStatus == 0)
{
System.Console.WriteLine("Response oid: " + response.InnerVariables[0].OID);
// The following Response is the Result
System.Console.WriteLine("Response value: " + response.InnerVariables[0].Data.ToString());
System.Console.WriteLine("");
}
else
{
System.Console.WriteLine("Response error code: " + response.ErrorStatus);
}

}
catch (Exception ex)
{
System.Console.WriteLine("Error in output: " + ex.Message);
}
The only thing i need to changed is : 1.3.6.1.2.1.1.5.0 ( a MIB-II object) to get an other one
      
I have like 10 different MIB-II object that will be in a loop for monitoring issue


If someone can only explain to me How class works and how a can run one of the objects i will try to do the others.