Custom COUNT SNMP script not working as expected

Dear all,

I have recently been tasked to create a custom script that will count the file number on /root folder.



Directory to check


Count the number of files in the directory

num_files=$(find “$directory” -type f | wc -l)

Output the number of files

echo $num_files

The script has been given permissions and when executed says “344”. i have made added the below extend entry on snmpd.conf:

extend countfiles /etc/snmp/

Then i navigated to LibreNMS Custom OID and did the below changes:

However, the result is constantly “0”.

Here are is the relevant output from the requested command ./poller.php -h -r -f -d | ./

I would honestly appreciate any assistance since this is a matter of life or death situation.

Thank you in advance,

Best Regards.

I’m seeing this in your poller output…

NET-SNMP-EXTEND-MIB::nsExtendOutputFull."countfiles": Unknown Object Identifier (Index out of range: "countfiles" (nsExtendToken))
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."countfiles": Unknown Object Identifier (Index out of range: "countfiles" (nsExtendToken))

What is the result if you manually run the snmpget command? Something like…

snmpget -v2c -c COMMUNITY -M /opt/librenms/mibs udp:HOSTNAME:161 NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\“countfiles\”

Hi @Slashdoom

The output of the requested command from librenms to the Asset is this:

NET-SNMP-EXTEND-MIB::nsExtendOutputFull.“countfiles”: Unknown Object Identifier (Index out of range: “countfiles” (nsExtendToken))

However, when i perform the command on the localhost, i get the result needed.

giannis@nobara-pc:/etc/snmp$ snmpwalk -v 2c -c gnet localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull."countfiles"
NET-SNMP-EXTEND-MIB::nsExtendOutputFull.“countfiles” = STRING: 344

What seems to be the issue?

Thank you for your prompt response.

Best Regards,

The full output of both the command and the result might help. Was snmpwalk used on both systems or was one snmpget and the other snmpwalk? You could also try using the numeric OID. I think it’s:

But you can use snmptranslate to be sure.

snmptranslate -On NET-SNMP-EXTEND-MIB::nsExtendOutputFull."countfiles"

On the asset i used snmpwalk(using localhost as hostname) and on the librenms i used snmpget (using the hostname).

Allow me to resend the command:


librenms:/opt/librenms# snmpget -v2c -c gnet -M /opt/librenms/mibs udp: NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\“countfiles\”

NET-SNMP-EXTEND-MIB::nsExtendOutputFull.“countfiles”: Unknown Object Identifier (Index out of range: “countfiles” (nsExtendToken))

Now regarding the snmptranslate it produced the below output on the Asset

giannis@nobara-pc:~$ snmptranslate -On NET-SNMP-EXTEND-MIB::nsExtendOutputFull.“countfiles”

NET-SNMP-EXTEND-MIB::nsExtendOutputFull.countfiles: Unknown Object Identifier (Index out of range: countfiles (nsExtendToken))

Thank you
Best Regards,

snmptranslate -On NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"countfiles\"

Also, make sure those are normal quotes, sometimes the forum converts them to left and right double quotes.

Then try to run snmpget with the numeric OID it returns.

snmpget -v2c -c gnet -M /opt/librenms/mibs udp: .

Oh wait!

I think you got it there :slight_smile:

Yes, the SNMPTRANSLATE and SNMPGET commands gave the expected output.

librenms:/opt/librenms# snmptranslate -On NET-SNMP-EXTEND-MIB::nsExtendOutputFull."countfiles"


librenms:/opt/librenms# snmpget -v2c -c gnet -M /opt/librenms/mibs udp: .


Thank you so much for the effort there.

But allow me to expand on the question. How did you know what OID did it use?

Did i miss something?

Best Regards,

Cool, so if you use the numeric OID (. in your custom OID does it return and chart the value you need or does it still give poller errors?

The idea here was just to use snmptranslate to get the numeric OID instead of the MIB string (NET-SNMP-EXTEND-MIB::nsExtendOutputFull.“countfiles”). The custom OID feature is not terribly mature, so it wouldn’t really surprise me if it has trouble properly escaping things like quotes and backslashes.

It seems to work as expected. The Poller works and even when i removed/added, it finally got there.

An extra question if you are aware, the count graph of the CUSTOM OID on the Asset’s main page hasn’t appeared (i thought it does automatically).

Any idea if i have to do something or it starts automatically?

Again thank you for your solution.

Best Regards,

It’ll probably take a few polls before it has enough info to display the RRD chart. I believe once that happens you can find it on the device under Graphs > Custom OID.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.