0

I want to build an app working like a SNMP device (such as switches etc) to monitor some items using snmp monitoring apps (like solarwinds, zabbix etc)

I use SNMPsharpNet component and successfully receive Get message, But I cannot respond to message, Look here:

UdpTarget target = new UdpTarget((IPAddress)new IpAddress(_peerIP.Address),162,5000,3);

nmpV2Packet pkt = new SnmpV2Packet();
try
{
    pkt.decode(_inbuffer, inlen);
}

pkt.Pdu.VbList.RemoveAt(0);

pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.1.0"), new OctetString("Micromoje")); //sysDescr
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.2.0"), new Oid("1.3.6.1.2.1.1.0")); //sysObjectID
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.3.0"), new TimeTicks(2324)); //sysUpTime
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.4.0"), new OctetString("DCU Nodes")); //sysContact
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.5.0"), new OctetString("DCU Managing")); //sysName

AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString("public"));

SnmpV2Packet response = new SnmpV2Packet("public");
response = target.Request(pkt.Pdu, aparam) as SnmpV2Packet;

when I use this code I receive the error message 'Request has reached maximum retries.'

then I tried this code:

pkt.Pdu.VbList.RemoveAt(0);

pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.1.0"), new OctetString("Micromoje")); //sysDescr
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.2.0"), new Oid("1.3.6.1.2.1.1.0")); //sysObjectID
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.3.0"), new TimeTicks(2324)); //sysUpTime
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.4.0"), new OctetString("DCU Nodes")); //sysContact
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.5.0"), new OctetString("DCU Managing")); //sysName   


SnmpV2Packet response = new SnmpV2Packet("public"); //= target.Request(pkt.Pdu, aparam) as SnmpV2Packet;
response.Pdu.SetVbList(pkt.Pdu.VbList);
response.Pdu.Type = PduType.Set;

try
{
    byte[] buf = response.encode();
    _socket.SendTo(buf, (EndPoint)_peerIP);
}

when I use this code I receive the error message 'does not respond with the supplied read/write community string' at monitoring system side

Finally I cannot connect my app as a SNMP device and test connections fails, please help me,

foxtrot2nov
  • 144
  • 2
  • 9
Kian
  • 13
  • 6
  • 1
    You are building an SNMP agent and I don't think SnmpSharpNet provides you the related functions. – Lex Li Jun 24 '16 at 00:08
  • 1
    have you any advise? – Kian Jun 24 '16 at 09:10
  • 1
    You might either switch to a commercial library who supports agent development, or check out #SNMP, http://docs.sharpsnmp.com/en/latest/samples/agent-development.html – Lex Li Jun 25 '16 at 04:43
  • Thank you Lex Li, I made an agent using sharpSnmp but my agent does not detect by Monitoring apps, what can I do? I made a topic here [link](http://stackoverflow.com/questions/38026934/how-can-i-reply-to-a-get-request-from-managing-software-such-as-solarwinds) please answer me there, thanks – Kian Jun 25 '16 at 10:12

1 Answers1

0

You need to answer with the same RequestId. Also the type should be PduType.Response. I updated your code:

int requestId = pkt.Pdu.RequestId;
pkt.Pdu.VbList.RemoveAt(0);

pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.1.0"), new OctetString("Micromoje")); //sysDescr
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.2.0"), new Oid("1.3.6.1.2.1.1.0")); //sysObjectID
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.3.0"), new TimeTicks(2324)); //sysUpTime
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.4.0"), new OctetString("DCU Nodes")); //sysContact
pkt.Pdu.VbList.Add(new Oid("1.3.6.1.2.1.1.5.0"), new OctetString("DCU Managing")); //sysName   


SnmpV2Packet response = new SnmpV2Packet("public"); //= target.Request(pkt.Pdu, param) as SnmpV2Packet;
response.Pdu.SetVbList(pkt.Pdu.VbList);
response.Pdu.Type = PduType.Response;
response.Pdu.RequestId = requestId;

try
{
    byte[] buf = response.encode();
    _socket.SendTo(buf, (EndPoint)_peerIP);
}
Ingo
  • 1