0

I'm working on a c++ code project that should be able to discover all the snmp devices on the network and then if the device name matches with one of the sensor names I'm looking for (I've got 2 different temperature sensors over Ethernet), then I want to send a snmpGet request which returns me the value(temperature).

I have no problem with the snmpGet part, but I'm having trouble figuring out a proper snmp discovery code. I'm using currently snmp++ library which I preferred over net-snmp because of its ease of use and support for C++. But I'm open to any recommendations to make this work.

Using snmpDiscovery code in snmp++ does not return any info for me. So I used snmpGet with broadcast address which seldomly returns one of the snmp device's info for each snmpGet call but not all snmp devices' info at once. So its unpredictable because even if one of my temperature sensors was available in the network, I would not know if my snmp-enabled-printer pings back instead. Anyway around this? Also I'm not using snmp version 3. Would it help if I do?

Thanks for the support!

  • 1
    Device discovery is not reliable by default. In most cases you should manually add the devices to the monitoring system. – Lex Li Dec 17 '18 at 13:51
  • I do know the 2 temperature sensor devices Im using. I also know their Oid as well to retrieve the temp value through snmp. But from the customer side, its not mandotory to have these 2 sensors plugged in the all the time. So first I want to know whether they are online or not, and perhaps which IP they have. I cannot know this for sure when some other snmp device is present in the network which pings back for my snmpget broadcast msg. – AJ Fernando Dec 19 '18 at 11:53
  • If sensors configuration is under your control your may consider using non-standard upd port range for snmp on them to reduce the chance of "false" discoveries. Or use some sensor-specific private mib oid in discovery if possible. Checking mac-addresses in arp replies to to broadcasts can also be used to quickly limit the scope of discovery, but that's not snmp. – Yuri Lachin Dec 29 '18 at 11:14

1 Answers1

0

They build entire companies around device discovery, so the problem is not easy.

As a short-cut, if you know the network addresses of your devices, you can traverse a range, eg. if you know they are in the 10.0.0/24 network, you can query eg. sysDescr for 10.0.0.1 to 10.0.0.254.

Gambit Support
  • 1,432
  • 1
  • 7
  • 17
  • I do query the known local network range as you said. Still the problem is that sometimes temp. sensor pings back but also sometimes the printer pings back instead. If both of them pings back, then it's okay because so that I can filter out through the value information received. But that's not the case. Only one replies. I cannot predict which one. And I cannot make the code so that, all the snmp devices in my local network will ping back to the snmpGet broadcast. thanks for the support! – AJ Fernando Dec 19 '18 at 11:46
  • Do NOT use broadcast, but unicast to each target in the range, ie.query 10.0.0.1, then 10.0.0.2, etc. Commercial offerings do this in parallel. – Gambit Support Dec 19 '18 at 13:40