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.

Script:

#!/bin/bash

Directory to check

directory=“/root/”

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/count_files.sh

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 192.168.178.153 -r -f -d | ./pbin.sh

https://p.libren.ms/view/3a29b2c9

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

Thank you in advance,

Best Regards.
Yiannis

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,
Yiannis

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:
.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.99.111.117.110.116.102.105.108.101.115

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:

SNMPGET FROM LIBRENMS TO ASSET:

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

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

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))
giannis@nobara-pc:~$

Thank you
Best Regards,
Yiannis

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:192.168.178.153:161 .1.3.6.1.4.1.8072.1.3.2.3.1.2.10.99.111.117.110.116.102.105.108.101.115

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"

.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.99.111.117.110.116.102.105.108.101.115

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

Amazing.

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,
Yiannis

Cool, so if you use the numeric OID (.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.99.111.117.110.116.102.105.108.101.115) 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,
Yiannis

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.