private SNMPSequence MakeVarbindList(AddrAndVar[] mibVar) { List <byte> varbindTypes = new List <byte>(); // Формирование VarBindType foreach (var mib in mibVar) { SNMPObject obj = new SNMPObject(mib.MibAddr); ISnmpVar var = SnmpVarFactory.CreateVar(mib.Type, mib.Var); SNMPSequence sequence = new SNMPSequence(SequenceType.Structure, obj.Get(), var.Get()); varbindTypes.AddRange(sequence.Get()); } SNMPSequence varbindList = new SNMPSequence(SequenceType.Structure, varbindTypes); return(varbindList); }
public ICustomActivityResult Execute() { agent = new Snmpagent(); dt = new DataTable("resultSet"); dt.Columns.Add("Result", typeof(string)); StringWriter sw = new StringWriter(); agent.RuntimeLicense = ""; agent.Reset(); agent.Objects.Clear(); switch (SNMPVersion) { case 1: agent.SNMPVersion = SnmpagentSNMPVersions.snmpverV1; if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId) { ObjectType = SNMPObjectTypes.otOctetString, Value = TrapValue }; agent.Objects.Add(snmpObj); agent.SendTrap(HostName, "ignoredbecausecustomobjectsspecified"); } else { agent.SendTrap(HostName, OId); } dt.Rows.Add("Success"); break; case 2: agent.SNMPVersion = SnmpagentSNMPVersions.snmpverV2c; if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId) { ObjectType = SNMPObjectTypes.otOctetString, Value = TrapValue }; agent.Objects.Add(snmpObj); agent.SendTrap(HostName, "ignoredbecausecustomobjectsspecified"); } else { agent.SendTrap(HostName, OId); } dt.Rows.Add("Success"); break; case 3: int encAlgo; int authAlgo; switch (EncMethod) { case "DES": encAlgo = 1; break; case "AES": encAlgo = 2; break; case "3DES": encAlgo = 3; break; default: encAlgo = 1; break; } switch (AuthMethod) { case "MD5": authAlgo = 1; break; case "SHA": authAlgo = 2; break; default: authAlgo = 1; break; } agent.SNMPVersion = SnmpagentSNMPVersions.snmpverV3; if (!string.IsNullOrEmpty(EngineID)) { agent.LocalEngineId = EngineID; } if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId) { ObjectType = SNMPObjectTypes.otOctetString, Value = TrapValue }; agent.Objects.Add(snmpObj); agent.SendSecureTrap(HostName, "ignoredbecausecustomobjectsspecified", UName, authAlgo, AuthPassword, encAlgo, EncPassword); } else { agent.SendSecureTrap(HostName, OId, UName, authAlgo, AuthPassword, encAlgo, EncPassword); } dt.Rows.Add("Success"); break; }// end switch agent.Dispose(); return(this.GenerateActivityResult(dt)); } //end Execute
public ICustomActivityResult Execute() { dt = new DataTable("resultSet"); dt.Columns.Add("Result", typeof(string)); StringWriter sw = new StringWriter(); if (string.IsNullOrEmpty(ValueType)) { throw new Exception("Value type is missing"); } agent.RuntimeLicense = ""; agent.Reset(); agent.Objects.Clear(); switch (SNMPVersion) { case 1: agent.SNMPVersion = SnmpmgrSNMPVersions.snmpverV1; if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId); if (ValueType.ToLower() == "string") { snmpObj.ObjectType = SNMPObjectTypes.otOctetString; } if (ValueType.ToLower() == "integer") { snmpObj.ObjectType = SNMPObjectTypes.otInteger; } snmpObj.Value = TrapValue; agent.Objects.Add(snmpObj); agent.RemoteHost = HostName; agent.Community = Community; agent.SendSetRequest(); } else { throw new Exception("Value is missing"); } dt.Rows.Add("Success"); break; case 2: agent.SNMPVersion = SnmpmgrSNMPVersions.snmpverV2c; if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId); if (ValueType.ToLower() == "string") { snmpObj.ObjectType = SNMPObjectTypes.otOctetString; } if (ValueType.ToLower() == "integer") { snmpObj.ObjectType = SNMPObjectTypes.otInteger; } snmpObj.Value = TrapValue; agent.Objects.Add(snmpObj); agent.RemoteHost = HostName; agent.Community = Community; agent.SendSetRequest(); } else { throw new Exception("Value is missing"); } dt.Rows.Add("Success"); break; case 3: int encAlgo; int authAlgo; switch (EncMethod) { case "DES": encAlgo = 1; break; case "AES": encAlgo = 2; break; case "3DES": encAlgo = 3; break; default: encAlgo = 1; break; } switch (AuthMethod) { case "MD5": authAlgo = 1; break; case "SHA": authAlgo = 2; break; default: authAlgo = 1; break; } agent.SNMPVersion = SnmpmgrSNMPVersions.snmpverV3; if (!String.IsNullOrEmpty(EngineID)) { agent.LocalEngineId = EngineID; } if (!string.IsNullOrEmpty(TrapValue)) { SNMPObject snmpObj = new SNMPObject(OId); if (ValueType.ToLower() == "string") { snmpObj.ObjectType = SNMPObjectTypes.otOctetString; } if (ValueType.ToLower() == "integer") { snmpObj.ObjectType = SNMPObjectTypes.otInteger; } snmpObj.Value = TrapValue; agent.Objects.Add(snmpObj); agent.RemoteHost = HostName; agent.Community = Community; agent.SendSetRequest(); //agent.SendSecureTrap(HostName, "ignoredbecausecustomobjectsspecified", UName, authAlgo, AuthPassword, encAlgo, EncPassword); } else { throw new Exception("Value is missing"); } dt.Rows.Add("Success"); break; }// end switch agent.Dispose(); return(this.GenerateActivityResult(dt)); } //end Execute