public Hw_MasterInfoResponse GetHw_MasterInfoData(int SiteId) { Hw_MasterInfoResponse response = new Hw_MasterInfoResponse(); try { return(response); } catch (Exception ex) { throw ex; } }
public Hw_MasterInfoResponse Hw_MasterInfo_InsertData(List <Hw_MasterInfoDTO> LstHw_MasterInfoDTO) { Hw_MasterInfoResponse response = new Hw_MasterInfoResponse(); try { foreach (Hw_MasterInfoDTO datarow in LstHw_MasterInfoDTO) { datarow.StatusId = 1; Hw_MasterInfo _Prb_Schedule = new Hw_MasterInfo() { HwMasterInfoId = datarow.HwMasterInfoId, SiteId = datarow.SiteId, ScheduleId = datarow.ScheduleId, HwTypeId = datarow.HwTypeId, DevType = datarow.DevType, DevCategory = datarow.DevCategory, ComType = datarow.ComType, HwName = datarow.HwName, Description = datarow.Description, IPAddress = datarow.IPAddress, MacAddress = datarow.MacAddress, StatusId = datarow.StatusId, CreatedBy = 1, CreatedDate = DateTime.Now, ModifiedBy = 1, ModifiedDate = DateTime.Now, IsDeleted = false, }; _Db.Hw_MasterInfo.Add(_Prb_Schedule); } _Db.SaveChanges(); return(response); } catch (Exception ex) { throw ex; } }
// Network Discovery Info //// hardware master information //List<Hw_MasterInfoDTO> LstHw_MasterInfoDTO = new List<Hw_MasterInfoDTO>(); //Hw_MasterInfoResponse oHw_MasterInfoResponse = new Hw_MasterInfoResponse(); //Hw_MasterInfoDataAccess oHw_MasterInfoDataAccess = new Hw_MasterInfoDataAccess(); #region SNMP Operations /// <summary> /// this method will pick basic information of switch /// throug SNMP and OIDs on the basis of IP Address and community /// /// </summary> public string SNMPGetRequest(string OctCommunity, string IpAddress) { List <Hw_MasterInfoDTO> LstHw_MasterInfoDTO = new List <Hw_MasterInfoDTO>(); var oHw_MasterInfoResponse = new Hw_MasterInfoResponse(); Hw_MasterInfoDataAccess oHw_MasterInfoDataAccess = new Hw_MasterInfoDataAccess(); string lstResults = ""; try { // SNMP community name OctetString community = new OctetString(OctCommunity); // Define agent parameters class AgentParameters param = new AgentParameters(community); // Set SNMP version to 1 (or 2) param.Version = SnmpVersion.Ver1; // Construct the agent address object // IpAddress class is easy to use here because // it will try to resolve constructor parameter if it doesn't // parse to an IP address IpAddress agent = new IpAddress(IpAddress); //IpAddress agent = new IpAddress("65.154.4.21"); // Construct target UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1); // Pdu class used for all requests Pdu pdu = new Pdu(PduType.Get); pdu.VbList.Add("1.3.6.1.2.1.1.1.0"); //sysDescr pdu.VbList.Add("1.3.6.1.2.1.1.2.0"); //sysObjectID pdu.VbList.Add("1.3.6.1.2.1.1.3.0"); //sysUpTime pdu.VbList.Add("1.3.6.1.2.1.1.4.0"); //sysContact pdu.VbList.Add("1.3.6.1.2.1.1.5.0"); //sysName // pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.12"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.13"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.14"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.15"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.16"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.17"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.18"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.19"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.20"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.21"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.22"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.23"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.24"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.25"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.26"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.27"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.28"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.29"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.1"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.2"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.3"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.4"); pdu.VbList.Add("1.3.6.1.2.1.2.2.1.2.5"); // // Make SNMP request SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param); Hw_MasterInfoDTO objHw_Info; // If result is null then agent didn't reply or we couldn't parse the reply. if (result != null) { // ErrorStatus other then 0 is an error returned by // the Agent - see SnmpConstants for error definitions if (result.Pdu.ErrorStatus != 0) { // agent reported an error with the request Console.WriteLine("Error in SNMP reply. Error {0} index {1}", result.Pdu.ErrorStatus, result.Pdu.ErrorIndex); } else { objHw_Info = new Hw_MasterInfoDTO(); objHw_Info.IPAddress = IpAddress; objHw_Info.HwTypeId = 7; // Switch TODO: it will be fetched from DataBase's table hardware type. objHw_Info.Description = result.Pdu.VbList[0].Value.ToString(); objHw_Info.HwName = result.Pdu.VbList[4].Value.ToString(); objHw_Info.DevType = "Machines"; objHw_Info.DevCategory = "IOS"; objHw_Info.ComType = "Cisco IOS Software"; objHw_Info.StatusId = 2; // // Start 1, Running 2, Completed 3, Stop 4, Exception 5... Status 3 is used for Complete Running Probe objHw_Info.MacAddress = ""; //TODO: will be fetched from Switch LstHw_MasterInfoDTO.Add(objHw_Info); if (LstHw_MasterInfoDTO.Count > 0) { // ProbeDBEntities _Db = new ProbeDBEntities(); oHw_MasterInfoResponse = oHw_MasterInfoDataAccess.Hw_MasterInfo_InsertData(LstHw_MasterInfoDTO); // By Umar } // Reply variables are returned in the same order as they were added // to the VbList lstResults = "System Description :" + result.Pdu.VbList[0].Value.ToString() + "\n"; Console.WriteLine("sysDescr({0}) ({1}): {2}", result.Pdu.VbList[0].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[0].Value.Type), result.Pdu.VbList[0].Value.ToString()); lstResults = lstResults + "System Object ID: " + result.Pdu.VbList[1].Value.ToString() + "\n"; Console.WriteLine("sysObjectID({0}) ({1}): {2}", result.Pdu.VbList[1].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[1].Value.Type), result.Pdu.VbList[1].Value.ToString()); lstResults = lstResults + "System Up Time: " + result.Pdu.VbList[2].Value.ToString() + "\n"; Console.WriteLine("sysUpTime({0}) ({1}): {2}", result.Pdu.VbList[2].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[2].Value.Type), result.Pdu.VbList[2].Value.ToString()); lstResults = lstResults + "System Conatct: " + result.Pdu.VbList[3].Value.ToString() + "\n"; Console.WriteLine("sysContact({0}) ({1}): {2}", result.Pdu.VbList[3].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[3].Value.Type), result.Pdu.VbList[3].Value.ToString()); lstResults = lstResults + "System Name: " + result.Pdu.VbList[4].Value.ToString() + "\n"; Console.WriteLine("sysName({0}) ({1}): {2}", result.Pdu.VbList[4].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[4].Value.Type), result.Pdu.VbList[4].Value.ToString()); } } else { Console.WriteLine("No response received from SNMP agent."); lstResults = "No response received from SNMP agent."; } target.Close(); } catch (Exception ex) { lstResults = "Code Breaks :" + ex.Message; return(lstResults); } //WriteTextFile.WriteErrorLog("============================ SWITCH Information ===================================="); // WriteTextFile.WriteErrorLog(lstResults); // WriteTextFile.WriteErrorLog("============================ SWITCH Information ===================================="); return(lstResults); }