Custom mibs are used partally only?

I am trying to read snmp data from my QNAP NAS.

To do this I downloaded the MIB from my NAS and mounted it in my telegraf docker container.
I also altered the snmp.conf to add a comment to the mibs : line.

My problem is that all the NAS-MIB:: OIDs not working - but the QTS-MIB:: OIDs do.

According to snmpexplorer both object identifier included in the MIB file provided by QNAP.

Here is my Dockerfile, building the telegraf image:

ARG TELEGRAF_VERSION

FROM telegraf:${TELEGRAF_VERSION}

RUN echo "deb http://http.us.debian.org/debian stable main contrib non-free" >> /etc/apt/sources.list.d/sources.list
RUN apt -y update && apt -y upgrade
RUN apt install -y unzip wget snmp-mibs-downloader
RUN wget https://github.com/hdecarne-github/fritzbox-telegraf-plugin/releases/download/v0.4.0/fritzbox-linux-amd64-0.4.0.zip
RUN unzip fritzbox-linux-amd64-0.4.0.zip -d /usr/local/bin/telegraf/
RUN sed -i 's/mibs :/#mibs :/g' /etc/snmp/snmp.conf

This is the telegraf part in my docker-compose.yml

  telegraf:
    build:
      context: telegraf/
      args:
        TELEGRAF_VERSION: latest
    hostname: "telegraf"
    container_name: telegraf
    depends_on:
      - influxdb
    volumes:
      - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - ./telegraf/fritzbox.conf:/etc/telegraf/fritzbox.conf
      - ./telegraf/telegraf.d/:/etc/telegraf/telegraf.d/
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./telegraf/snmp/mibs/qnap.mib:/usr/share/snmp/mibs/NAS.mib
    environment:
      -USER: "telegraf"
      -INFLUX_PASSWORD: "ChangeMe!"
    networks:
      - influx

When doing some troubleshooting I can successfully grab QTS-MIB::enclosureName.1 but nothing from the NAS-MIB:: context :frowning:

root@telegraf:/# snmpwalk -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 NAS-MIB::cpuTable
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier

root@telegraf:/# snmpwalk -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 QTS-MIB::cpuTable
QTS-MIB::cpuTable: Unknown Object Identifier

root@telegraf:/# snmpwalk -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 NAS-MIB::enclosureName.1
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::enclosureName.1: Unknown Object Identifier

root@telegraf:/# snmpwalk -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 QTS-MIB::enclosureName.1
QTS-MIB::enclosureName.1 = STRING: "li2nas1"

root@telegraf:/# snmptable -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 NAS-MIB::cpuTable
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier

root@telegraf:/# snmptable -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 QTS-MIB::cpuTable
QTS-MIB::cpuTable: Unknown Object Identifier
root@telegraf:/#

Any ideas what am I doing wrong?

Hi,

fritzbox-telegraf-plugin

This is not telegraf, but someone’s custom plugin. We have no way of supporting that.

I am not talking about the fritzbox plugin - this is working perfectly.

I am talking only about the telegraf SNMP.input plugin.

Meanwhile I was troubleshooting a bit further with somewhat confusing results.

This is the config file I am using:

[[inputs.snmp]]
   # List of agents to poll
   agents = [ "udp://192.168.x.x:161" ]
   # Polling interval
   interval = "30s"
   # Timeout for each SNMP query.
   timeout = "30s"
   # Number of retries to attempt within timeout.
   retries = 3
   # The GETBULK max-repetitions parameter
   max_repetitions = 10
   # Measurement name
   name = "snmp.QNAP"
   #SNMPv3
   version = 3
   sec_name = ""
   auth_protocol = "SHA"
   auth_password = ""
   sec_level = "authPriv"
   priv_protocol = "DES"
   priv_password = ""

   # Search path
   path = ["/usr/share/snmp/mibs"]

  ##
  ## System Details & Metrics
  ##
  # CPU
  [[inputs.snmp.field]]
    name = "name"
    oid = "QTS-MIB::enclosureName.1"
    is_tag = true

#  [[inputs.snmp.table]]
#    name = "snmp.QNAP.cpuTable"
#    #oid = "NAS-MIB::cpuTable"
#    oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3"
#    [[inputs.snmp.table.field]]
#      name = "cpuIndex"
#      #oid = "NAS-MIB::cpuIndex"
#      oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.1"
#      is_tag = true
#    [[inputs.snmp.table.field]]
#      name = "cpuID"
#      oid = "NAS-MIB::cpuID"
#      #oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.2"
#      is_tag = true
#    [[inputs.snmp.table.field]]
#      name = "cpuUsage"
#      #oid = "NAS-MIB::cpuUsage"
#      oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.3"

As shown here the config loads fine and I don’t get error messages.
After uncommenting the cpuTable part it doesn’t matter if I am using either of the following oids

  • NAS-MIB::cpuTable
  • QTS-MIB::cpuTable
  • .1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3

all coming up with the same error message:

[telegraf] Error running agent: could not initialize input inputs.snmp: initializing table snmp.QNAP.cpuTable: getting table columns: MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier: exit status 1

this would normally show that the according MIB is not found by the system - however the NAS-MIB as well as the numbered oid are defined in the same file as the QTS-MIB which successfully resolves with the QTS-MIB::enclosureName.1.

I am also tried to use snmptranslate to find if these oid are generally present within the container:

root@telegraf:/# snmptranslate -Tt -m /usr/share/snmp/mibs/NAS.mib | grep cpuTable
                            cpuTable(3) type=0
                              cpuTableEntry(1) type=0
root@telegraf:/# snmptranslate -Tt -m all | grep cpuTable
Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
                            cpuTable(3) type=0
                              cpuTableEntry(1) type=0
root@telegraf:/#
root@telegraf:/# snmptranslate -Td -m all NAS-MIB::cpuTable
Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
NAS-MIB::cpuTable
cpuTable OBJECT-TYPE
  -- FROM       NAS-MIB
  MAX-ACCESS    not-accessible
  STATUS        current
  DESCRIPTION   "A list of CPUs.  The number of
            entries is given by the value of CPUNumber."
::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) storage(24681) storageSystem(1) storageSystemEx(4) systemSettings(1) storageManager(1) nasStorage(1) components(1) cpu(4) 3 }
root@telegraf:/#
root@telegraf:/# snmptranslate -Td -m /usr/share/snmp/mibs/NAS.mib .1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3
NAS-MIB::cpuTable
cpuTable OBJECT-TYPE
  -- FROM       NAS-MIB
  MAX-ACCESS    not-accessible
  STATUS        current
  DESCRIPTION   "A list of CPUs.  The number of
            entries is given by the value of CPUNumber."
::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) storage(24681) storageSystem(1) storageSystemEx(4) systemSettings(1) storageManager(1) nasStorage(1) components(1) cpu(4) 3 }
root@telegraf:/#

Any help would be higly appreciated!

root@telegraf:/# snmptable -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 NAS-MIB::cpuTable
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier

root@telegraf:/# snmptable -u USER -a SHA -A ChangeMe! -x DES -X ChangeMe! -l authPriv 192.168.30.2 QTS-MIB::cpuTable
QTS-MIB::cpuTable: Unknown Object Identifier

This looks like snmptable is not able to find these either, which means telegraf certainly will not either.

This previous thread mentions needing to have snmp-mibs-downloader and download-mibs also this issue, walks a couple users through needing to ensure:

  • MIBS are available locally, which you say they are
  • Ensure that the permissions on the files are valid for other users, worth checking
  • Needing the additional SNMP packages

edit:

I am also tried to use snmptranslate to find if these oid are generally present within the container:

I would still try the above items. If you have it working on the container you are running telegraf, then it is probably a permissions issue with read the mibs. i.e. the telegraf user cannot read the file or something similar.

Thanks for your response.

I doublechecked

  • MIBS are locally available – they are.
  • Permissions are all set to root by default as telegraf is running as root in the container
  • Added download-mibs in the Dockerfile to ensure the MIBS are updated within the container

After build and recreating the container, I still get the error message that telegraf is not finding the right module.

I then tried to reference the exact MIBS file in the path option within the configuration - didn’t help either :frowning:

I am also searching the web and all i find is the description of the process I am actually following. I believe it something totally simple, like typo somewhere but I just don’t see it.

You are running it with sudo or as a service? If it is as a service, telegraf is not running as root. We use the “telegraf” user to run the service.

Can you run ls -la /usr/share/snmp/mibs

It actually is a Docker container where telegraf is started in the entrypoint.sh.

Here the output from whoami and ls within the docker container:

[admin@ influxdb]# docker exec telegraf whoami
root
[admin@ influxdb]# docker exec telegraf ls -la /usr/share/snmp/mibs
total 312
drwxr-xr-x 1 root root   4096 Jan 19 14:47 .
drwxr-xr-x 1 root root   4096 Jan 18 15:10 ..
-rw-r--r-- 1 root root   5931 Jan  3  2023 LM-SENSORS-MIB.txt
-rw-r--r-- 1 root root 148599 Jan 18 14:10 NAS.mib
-rw-r--r-- 1 root root  15901 Jan  3  2023 NET-SNMP-AGENT-MIB.txt
-rw-r--r-- 1 root root   9160 Jan  3  2023 NET-SNMP-EXAMPLES-MIB.txt
-rw-r--r-- 1 root root   9326 Jan  3  2023 NET-SNMP-EXTEND-MIB.txt
-rw-r--r-- 1 root root   2036 Jan  3  2023 NET-SNMP-MIB.txt
-rw-r--r-- 1 root root   3730 Jan  3  2023 NET-SNMP-PASS-MIB.txt
-rw-r--r-- 1 root root   4814 Jan  3  2023 NET-SNMP-TC.txt
-rw-r--r-- 1 root root   5039 Jan  3  2023 NET-SNMP-VACM-MIB.txt
-rw-r--r-- 1 root root   2163 Jan  3  2023 UCD-DEMO-MIB.txt
-rw-r--r-- 1 root root   4965 Jan  3  2023 UCD-DISKIO-MIB.txt
-rw-r--r-- 1 root root   3087 Jan  3  2023 UCD-DLMOD-MIB.txt
-rw-r--r-- 1 root root   8118 Jan  3  2023 UCD-IPFWACC-MIB.txt
-rw-r--r-- 1 root root  53338 Jan  3  2023 UCD-SNMP-MIB.txt
lrwxrwxrwx 1 root root     18 Aug  7  2020 iana -> /var/lib/mibs/iana
lrwxrwxrwx 1 root root     18 Aug  7  2020 ietf -> /var/lib/mibs/ietf
[admin@li2nas1 influxdb]#

edit:
Before it gets confusing - I just changed the filename of the NAS MIB mimicing the same structure as the others:

[admin@ influxdb]# docker exec telegraf ls -la /usr/share/snmp/mibs
total 312
drwxr-xr-x 1 root root   4096 Jan 19 15:30 .
drwxr-xr-x 1 root root   4096 Jan 18 15:10 ..
-rw-r--r-- 1 root root   5931 Jan  3  2023 LM-SENSORS-MIB.txt
-rw-r--r-- 1 root root 148599 Jan 18 14:10 NAS-MIB.txt
-rw-r--r-- 1 root root  15901 Jan  3  2023 NET-SNMP-AGENT-MIB.txt
-rw-r--r-- 1 root root   9160 Jan  3  2023 NET-SNMP-EXAMPLES-MIB.txt
-rw-r--r-- 1 root root   9326 Jan  3  2023 NET-SNMP-EXTEND-MIB.txt
-rw-r--r-- 1 root root   2036 Jan  3  2023 NET-SNMP-MIB.txt
-rw-r--r-- 1 root root   3730 Jan  3  2023 NET-SNMP-PASS-MIB.txt
-rw-r--r-- 1 root root   4814 Jan  3  2023 NET-SNMP-TC.txt
-rw-r--r-- 1 root root   5039 Jan  3  2023 NET-SNMP-VACM-MIB.txt
-rw-r--r-- 1 root root   2163 Jan  3  2023 UCD-DEMO-MIB.txt
-rw-r--r-- 1 root root   4965 Jan  3  2023 UCD-DISKIO-MIB.txt
-rw-r--r-- 1 root root   3087 Jan  3  2023 UCD-DLMOD-MIB.txt
-rw-r--r-- 1 root root   8118 Jan  3  2023 UCD-IPFWACC-MIB.txt
-rw-r--r-- 1 root root  53338 Jan  3  2023 UCD-SNMP-MIB.txt
lrwxrwxrwx 1 root root     18 Aug  7  2020 iana -> /var/lib/mibs/iana
lrwxrwxrwx 1 root root     18 Aug  7  2020 ietf -> /var/lib/mibs/ietf
[admin@ influxdb]#

This also makes no difference.

edit 2:
I also tried to upload the MIBS file to the container and remove the mount from the docker-compose file.

Didn’t change anything either.

I also tried to cat the content of the uploaded MIBS file with the user telegraf is running with (just to make sure) and this works fine. Hence, I believe this is not a permission issue.

FYI the default entrypoint does not run telegraf as root, so do not assume it is running as root unless you are customizing this or setting some other variable.

That said, those permissions look fine.

Two thoughts:

  1. Can you enable debug in telegraf, and provide the logs?
  2. Run your snmptranslate command as the telegraf user.

Thanks for your help!

My assumption with docker is that if I am attaching to the container, without specifying a dedicated user, I always end up with the user the entrypoint.sh is running in and under which user the processes are started. You are right - I wasn’t doublechecking this and it look like that telegraf is running under the telegraf user.

As the file permissions are everyone read - that shouldn’t be an issue - right?

But this brings me to another question - do I need to change something in the entrypoint to get the additional MIBS working? Because I haven’t changed here anything and use the entrypoint provided by the telegraf image.

I hope I have turned debugging on with my changed telegraf.conf:

[agent]
  debug = "true"

[global_tags]
  user = "telegraf"
  

# For InfluxDB 1.x:
[[outputs.influxdb]]
  urls = ["http://influxdb:8086"]
  password = "${INFLUX_PASSWORD}"

here is the result:

2024-01-19T16:15:47Z I! Loading config: /etc/telegraf/telegraf.conf
2024-01-19T16:15:47Z I! Loading config: /etc/telegraf/telegraf.d/qnap.conf
2024-01-19T16:15:47Z I! Starting Telegraf 1.29.1 brought to you by InfluxData the makers of InfluxDB
2024-01-19T16:15:47Z I! Available plugins: 241 inputs, 9 aggregators, 30 processors, 24 parsers, 60 outputs, 6 secret-stores
2024-01-19T16:15:47Z I! Loaded inputs: snmp
2024-01-19T16:15:47Z I! Loaded aggregators:
2024-01-19T16:15:47Z I! Loaded processors:
2024-01-19T16:15:47Z I! Loaded secretstores:
2024-01-19T16:15:47Z I! Loaded outputs: influxdb
2024-01-19T16:15:47Z I! Tags enabled: host=telegraf user=telegraf
2024-01-19T16:15:47Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegraf", Flush Interval:10s
2024-01-19T16:15:47Z D! [agent] Initializing plugins
2024-01-19T16:15:47Z D! [inputs.snmp] executing "snmptranslate" "-Td" "-Ob" "NAS-MIB::cpuTable"
2024-01-19T16:15:47Z E! [telegraf] Error running agent: could not initialize input inputs.snmp: initializing table snmp.QNAP.cpuTable: translating: MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier: exit status 2

not much of a difference but the single line with snmptranslate.

Executing this command in the container directly it also comes up with a error, but adding the path to the command it works:

[admin@ influxdb]# docker exec -ti -u telegraf telegraf snmptranslate -Td -Ob NAS-MIB::cpuTable
MIB search path: /etc/telegraf/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
Cannot find module (NAS-MIB): At line 1 in (none)
NAS-MIB::cpuTable: Unknown Object Identifier


[admin@ influxdb]# docker exec -ti -u telegraf telegraf snmptranslate -Td -Ob -m /usr/share/snmp/mibs/QNAP-MIB.txt NAS-MIB::cpuTable
NAS-MIB::cpuTable
cpuTable OBJECT-TYPE
  -- FROM       NAS-MIB
  MAX-ACCESS    not-accessible
  STATUS        current
  DESCRIPTION   "A list of CPUs.  The number of
            entries is given by the value of CPUNumber."
::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) storage(24681) storageSystem(1) storageSystemEx(4) systemSettings(1) storageManager(1) nasStorage(1) components(1) cpu(4) 3 }
[admin@ influxdb]#

What I am wondering is why the MIBS are not used?

I know there is that dependency on the /etc/snmp/snmp.conf where that comment needs to be added to enable additional MIBS. But I changed that file accordingly:

root@telegraf:/# cat /etc/snmp/snmp.conf
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
#mibs :

# If you want to globally change where snmp libraries, commands and daemons
# look for MIBS, change the line below. Note you can set this for individual
# tools with the -M option or MIBDIRS environment variable.
#
# mibdirs /usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
root@telegraf:/#

What I am also wondering - I have added the path option within the [[inputs.snmp]] section. Why isn’t this path added to the snmptranslate command?

Yeah I agree

I hope I have turned debugging on with my changed telegraf.conf:

yep that looks right for debug.

do I need to change something in the entrypoint to get the additional MIBS working?

Thanks for trying with the snmptranslate command. It looks like it only worked when you specifically added that file?

My guess at this point, having not done much with SNMP, is that the telegraf config either is:

1- needs the path updates to include that SNMP file
2- the config in telegraf is pointing at the wrong OID

Let’s try number 2 first. Looking at a previous table SNMP issue as a guide, it looks like you have the table at .1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3, and then want fields under that, so something like:

[[inputs.snmp.table]]
  name = "cpu"
[[inputs.snmp.table.field]]
   oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.1"
   name = "index"
[[inputs.snmp.table.field]]
   oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.2"
   name = "id"
[[inputs.snmp.table.field]]
   oid = ".1.3.6.1.4.1.24681.1.4.1.1.1.1.4.3.1.3"
   name = "usage"

I know you had something similar commented out, but note this is slightly different in that the fields define the oids.

While thinking about that issue I really wondered why snmptranslate is showing the right path but is not picking up the MIBS provided.
I thought I’ll just use another way of providing that information to snmp and added an MIBS environment variable to the system and guess what…
Thats was the solution, now snmptranslate is picking up the whole MIBS file and everything is working.

@jpowers: Thank you very much for your help!

1 Like

Hi, did you see this section in the documentation?

  ## Path to mib files
  ## Used by the gosmi translator.
  ## To add paths when translating with netsnmp, use the MIBDIRS environment variable
  # path = ["/usr/share/snmp/mibs"]

So changing this value does nothing if you didn’t set the Agent config setting snmp_translator to "gosmi".