private void AddToMibListing(StreamReader sr, string line) { TranslateMibInfo tmi = new TranslateMibInfo(""); MibEnt mib = new MibEnt(); OidEnt oid = new OidEnt(); bool bDone = false; mib.Title = GetOidName(line); while (sr.Peek() != -1 && !bDone) { if (line.Contains("::=")) { GetParentValue(oid, line); mib.Parent = oid.Parent; mib.Value = int.Parse(oid.Value); if (!tmi.FoundMibEnt(_listMibParents, mib)) { _listMibParents.Add(mib); } bDone = true; } line = sr.ReadLine().Trim(); } }
public string BuildOidStringValue(OidEnt oid) { string oidValue = string.Empty; oidValue = GetOidValue(oid.Parent); if (!string.IsNullOrEmpty(oidValue)) { if (oidValue[0].Equals('.')) { oidValue = oidValue.Substring(1); } if (!oidValue.StartsWith(HP_OID)) { string value = HP_OID; if (!oidValue.Contains(DM_OID)) { value += "." + DM_OID; } oidValue = value + "." + oidValue; } } oidValue += "." + oid.Value; return(oidValue); }
private void AddToOidList() { ListOidEnt notFound = new ListOidEnt(); foreach (OidInfo oInfo in _listOidInfo) { bool bFound = false; foreach (OidEnt oid in _listOids) { if (oid.OidIndex.Contains(oInfo.OIDValue)) { bFound = true; // OID was not in MIB but provided from the HP Device if (oid.OidName.Equals(string.Empty)) { oid.OidName = oInfo.NameOid; oid.OidString = oInfo.OIDValue; oid.Usage = USAGES.eMcHpDevice; } else { switch (oid.Usage) { case USAGES.eMib: oid.Usage = USAGES.eMcMib; break; case USAGES.eHpDeviceMib: oid.Usage = USAGES.eAll; break; } } } } if (!bFound) { OidEnt temp = new OidEnt(); temp.OidName = oInfo.NameOid; temp.OidString = oInfo.OIDValue; temp.OidIndex = oInfo.SupportedIdxStr(); temp.OidIndexValue = oInfo.ExpectedValue; temp.Access = oInfo.Access(); temp.Syntax.Add(Enum <SNMP_DATATYPES> .Value(oInfo.DataType)); temp.Status = oInfo.Implementation; temp.Usage = USAGES.eMc; notFound.Add(temp); } } if (notFound.Count > 0) { foreach (OidEnt oid in notFound) { _listOids.Add(oid); } } }
private void GetParentValue(OidEnt oidInfo, string line) { string[] data = line.Split(SEPARATORS, StringSplitOptions.RemoveEmptyEntries); // If there is a space in the parent name... int last = data.Count() - 1; oidInfo.Value = data[last]; for (int idx = 0; idx < last; idx++) { oidInfo.Parent += data[idx]; } }
private bool OidInfoComplete(OidEnt oidInfo) { bool bComplete = false; if (!string.IsNullOrEmpty(oidInfo.Value) && !string.IsNullOrEmpty(oidInfo.Parent) && !string.IsNullOrEmpty(oidInfo.OidName) && !string.IsNullOrEmpty(oidInfo.Access) && !string.IsNullOrEmpty(oidInfo.Status) && !string.IsNullOrEmpty(oidInfo.Description) && oidInfo.Syntax.Count() > 0) { bComplete = true; } return(bComplete); }
private bool OidEntFound(OidEnt oid) { bool bFound = false; foreach (OidEnt ent in _listOids) { if (oid.Equals(ent)) { bFound = true; break; } } return(bFound); }
private void BuildOidObject(StreamReader sr, string line) { if (_oidInfo == null) { _oidInfo = new OidEnt(); } CurrentLine = string.Empty; switch (OidType) { case OID_TYPES.oidList: _oidInfo.OidString = GetOidString(line); break; case OID_TYPES.name: _oidInfo.OidName = GetOidName(line); break; case OID_TYPES.syntax: _oidInfo.Syntax = GetSyntaxListing(sr, line); break; case OID_TYPES.access: _oidInfo.Access = GetStatusOrAccess(line); break; case OID_TYPES.status: _oidInfo.Status = GetStatusOrAccess(line); break; case OID_TYPES.description: _oidInfo.Description = GetDescription(sr, line); break; case OID_TYPES.parentLine: GetParentValue(_oidInfo, line); break; case OID_TYPES.mibEnt: AddToMibListing(sr, line); break; } if (OidInfoComplete(_oidInfo)) { _oidInfo.Usage = USAGES.eMib; if (string.IsNullOrEmpty(_oidInfo.OidString)) { BuildOidString(); } OidsListing.Add(_oidInfo); _oidInfo = null; } }
private void GetDeviceOidListing() { DeviceOids device = new DeviceOids(_password, txtIpAddr.Text, txtOidValue.Text); if (device.ValidateEngine()) { ListOidEnt tmpOidList = new ListOidEnt(); lblReleaseName.Text = device.ReleaseName; lblReleaseName.Refresh(); device.GetDeviceOidListings(); foreach (DeviceOidEnt dOid in device.ListDeviceOids) { bool bFound = false; foreach (OidEnt oidInfo in _listOids) { string temp = oidInfo.OidString + "."; if (dOid.OidString.Contains(temp)) { bFound = true; AddOidData(oidInfo, dOid, tmpOidList); } } if (!bFound) { OidEnt oid = new OidEnt(); oid.OidIndex = dOid.OidString; oid.OidIndexValue = dOid.OidValue; oid.Usage = USAGES.eHPDevice; tmpOidList.Add(oid); } } foreach (OidEnt oid in tmpOidList) { _listOids.Add(oid); } } else { MessageBox.Show(device.GetLastError); } }
private void AddOidData(OidEnt oidInfo, DeviceOidEnt dOid, ListOidEnt tmpOidList) { if (string.IsNullOrEmpty(oidInfo.OidIndex)) { oidInfo.OidIndex = dOid.OidString; oidInfo.OidIndexValue = dOid.OidValue; oidInfo.Usage = USAGES.eHpDeviceMib; } else { // same family but a different index, so making a copy and setting same OID with different index OidEnt oid = new OidEnt(oidInfo); oid.OidIndex = dOid.OidString; oid.OidIndexValue = dOid.OidValue; oidInfo.Usage = USAGES.eHpDeviceMib; oid.Usage = USAGES.eHpDeviceMib; tmpOidList.Add(oid); } }
public OidEnt(OidEnt copy) { this.OidName = copy.OidName; this.OidString = copy.OidString; this.Access = copy.Access; this.Status = copy.Status; this.Description = copy.Description; this.Parent = copy.Parent; this.Value = copy.Value; this.OidIndex = copy.OidIndex; this.OidIndexValue = copy.OidIndexValue; this.Usage = copy.Usage; this.Syntax = new List <string>(); foreach (string str in copy.Syntax) { this.Syntax.Add(str); } }
private void CheckIfOidsBuiltCorrectly() { ListOidEnt listNotFound = new ListOidEnt(); foreach (OidEnt oidInfo in _listOids) { string oidValue = GetOidValue(oidInfo.Parent); if (oidValue.Contains(HP_OID)) { if (oidValue[0].Equals('.')) { oidValue = oidValue.Substring(1); } } else { oidValue = HP_OID + oidValue; } oidValue += "." + oidInfo.Value; // The parent values aren't building correctly if (!oidValue.Equals(oidInfo.OidString)) { OidEnt temp = new OidEnt(oidInfo); temp.OidIndex = oidValue; temp.OidIndexValue = string.Empty; temp.Usage = USAGES.eUnknown; listNotFound.Add(temp); } } if (listNotFound.Count > 0) { WriteFile wf = new WriteFile(listNotFound); wf.WritePartOInfoFile(); MessageBox.Show(listNotFound.Count.ToString() + " building of parent values not matching stated MIB OID."); } }