Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SNMP OUTPUT OPTIONS - How do I get the OID response value only?

I have to go through and collect a few OIDs from some SNMP enabled network printers with a BASH script I have been working on.

My Request:

snmpget -v2c -c public 192.168.0.77 
.1.3.6.1.2.1.1.1 
.1.3.6.1.2.1.1.2 

My Actual Response:

 .1.3.6.1.2.1.1.1 = Counter32: 1974 
 .1.3.6.1.2.1.1.2 = Counter32: 633940

The Desired Response:

1974
633940314

(just the oid values only)

I looked and tested several options using the resource from the site below:

http://www.netsnmp.org/docs/man/snmpcmd.html#lbAF

-Oq removes '=' so running

snmpget -v2c -c public -Oq 10.15.105.133
.1.3.6.1.2.1.1.1 
.1.3.6.1.2.1.1.2 

returns

.1.3.6.1.2.1.1.1 Counter32: 1974
.1.3.6.1.2.1.1.2 Counter 32: 633940314

so I know I am phrasing my request properly.

I am taking the values and writing them to a MYSQL dB, I set the data types in my tale schema, the request is consistent so I know the definition of the OID, so I do not need all the information I am getting back, just the value of the OID itself, so I can write it to my dB without manipulating the the response. I probably can manipulate the response pulling the information to the right of ":" and writing the value of the OID.

I am relatively new to SNMP (http://www.net-snmp.org/), but I can not see why this is not a more commonly asked question because I have been searching everywhere for an answer and this post is my last recourse...

like image 821
user2179455 Avatar asked Apr 01 '15 09:04

user2179455


People also ask

How does SNMP tester find the OID?

After some time, depending on the amount of SNMP information provided by the target device, SNMP Tester will list all OIDs it could find with their current value and value type. The type is important to add the correct SNMP Custom sensor type to request a specific OID.

How do I pull data from a device with SNMP?

Pulling data from devices with SNMP can be done one of two ways; with an SNMP Get request or an SNMP Trap. An SNMP Get Request is where the user polls the device for performance data. Once the SNMP agent receives this request it sends back OIDs that can be read by an SNMP monitoring system.

What is an SNMP get request and SNMP trap?

An SNMP Get Request is where the user polls the device for performance data. Once the SNMP agent receives this request it sends back OIDs that can be read by an SNMP monitoring system. WIth SNMP traps, the SNMP agent notifies the SNMP manager automatically once a significant event occurs on the device.

What is the snmpv2-mib numerical value for a custom OID?

Mentioned OID is SNMPv2-MIB::sysDescr.0, with numric value .1.3.6.1.2.1.1.1.0 Show activity on this post. From that, you get what looks like on OID.


1 Answers

You can tune the output with the -O argument:

snmpgetnext -Oqv -v 2c -c public 192.168.0.77 .1
2

See the --help:

q:  quick print for easier parsing
v:  print values only (not OID = value)
like image 64
steffen Avatar answered Sep 20 '22 23:09

steffen