Just some short notes and explanations about the SNMP utilities in Linux - just so that I don't have to search for them again when I forget what I have just learned.

  • the SNMP daemon is configured in /etc/snmpd/snmp.conf. Example:
    com2sec local        mySecRETpassWORD
    com2sec local             mySecRETpassWORD
    #com2sec local       my-own-SNMP-community
    group MyROGroup v1         local
    group MyROGroup v2c        local
    group MyROGroup usm        local
    view all    included  .1                               80
    access MyROGroup "" any     noauth    exact  all    none   none
    syslocation Moon
    syscontact Admin {rock@moon.com}
    Using this configuration file, all clients connecting from hosts having the IP addresses 192.168.* and and presenting the password "mySecRETpassWORD" will be able to get values out of SNMP (no clue about setting them).
  • The SNMP-logfile in Gentoo is "/var/log/net-snmpd.log".
  • Generate the full list of all MIBs/OIDs and their details:
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 .1
  • Generate the same list of all MIBs and their details, displaying the resulting OIDs in numerical form instead of text:
    snmpwalk -v2c -c mySecRETpassWORD -On localhost:161 .1
  • If you don't get back anything check that 1) the community/password is correct and 2) that the IP number you are using matches the one you have configured in /etc/snmpd/snmpd.conf.
  • The command...
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 .
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIODevice
    ...are equivalent.
  • The definition of what you can get is in "/usr/share/snmp/mibs".
  • If e.g. in /usr/share/snmp/mibs/UCD-DISKIO-MIB.txt you see that "diskIONWrittenX" has "diskIOEntry 13" you'll know that you'll be interested in the entry number 13.
    Therefore, issuing...
    snmpwalk -v2c -c mypwd localhost:161 .
    snmpwalk -v2c -c mypwd localhost:161 UCD-DISKIO-MIB::diskIONWrittenX
    snmpwalk -v2c -c mypwd localhost:161 .
    ...generates the same result.
  • Running the command...
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIODevice
    ...will show e.g. the line...
    UCD-DISKIO-MIB::diskIODevice.9 = STRING: sda
    ...and by seeing that you'll know that when you run...
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIONWrittenX
    ...you'kll have to focus on...
    UCD-DISKIO-MIB::diskIONWrittenX.9 = Counter64: 2136883200
    ...for the 64bit integer value concerning the disk "sda".

    If you want to  get only the value of that single disk then issue:
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIONWrittenX.9
    snmpget -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIONWrittenX.9

  • In the end, run this to get the list of all devices...
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIODevice
    ...getting back e.g. ...
    UCD-DISKIO-MIB::diskIODevice.8 = STRING: loop7
    UCD-DISKIO-MIB::diskIODevice.9 = STRING: sda
    UCD-DISKIO-MIB::diskIODevice.10 = STRING: sda1
    ...then grep for the device you're interested in like...
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIODevice | grep sda
    ...then check that the string you found matches exactly what you were looking for (e.g. ignore "sda1" if you were looking for "sda") and finally replace for that line the "diskIODevice" with "diskIONWrittenX" to get the specific value of (in this case) a 64bit int showing the bytes written to that device since the last boot:
    snmpwalk -v2c -c mySecRETpassWORD localhost:161 UCD-DISKIO-MIB::diskIONWrittenX.9 | awk '{print $4}'