What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

SNMP Custom OID

Thorgear

Regular Contributor
I need to define a custom OID. I think the correct place to do it is in /tmp/snmpd.conf, but that's a temporary file. Does anyone know the correct place to define the custom OID?
 
Ah, right. I forgot that I wasn't in a Merlin forum. It's an ASUS AC68 running Merlin 380_60_beta2, but I think the answer is applicable to my other Merlin routers. I'm adding this line to /tmp/snmpd.conf:
Code:
exec .1.3.6.1.4.1.32473.8.1 gfgf /opt/gf.sh
I can add it and restart snmpd in a startup script, but I'd rather do it the right way, if there is such a thing.
 
Ah, right. I forgot that I wasn't in a Merlin forum. It's an ASUS AC68 running Merlin 380_60_beta2, but I think the answer is applicable to my other Merlin routers. I'm adding this line to /tmp/snmpd.conf:
Code:
exec .1.3.6.1.4.1.32473.8.1 gfgf /opt/gf.sh
I can add it and restart snmpd in a startup script, but I'd rather do it the right way, if there is such a thing.

The documentation is your best friend here:

https://github.com/RMerl/asuswrt-merlin/wiki/Custom-config-files
 
I have a follow-up question. One of the things I'm trying to do is get back a rough memory-free percentage for a PRTG sensor. In this case, it's from a Tomato router. These are the changes I'm making and the results.

Code:
Tomato router: snmpd.conf:
sh .1.3.6.1.4.1.32473.8.2 memfree /jffs/memfree.sh

Tomato router: memfree.sh:
cat /proc/meminfo | awk '/MemFree/ {free=$2} /MemTotal/ {total=$2} END {printf ("%2.2f\n", (free/total)*100)}'

Windows client:
c:\usr\bin\snmpwalk.exe -v 2c -c public 10.0.3.1 .1.3.6.1.4.1.32473.8.2

Result:
SNMPv2-SMI::enterprises.32473.8.2.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.32473.8.2.2.1 = STRING: "memfree"
SNMPv2-SMI::enterprises.32473.8.2.3.1 = STRING: "/jffs/memfree.sh"
SNMPv2-SMI::enterprises.32473.8.2.100.1 = INTEGER: 0
SNMPv2-SMI::enterprises.32473.8.2.102.1 = INTEGER: 0

The same changes work fine on a Merlin router.

Code:
SNMPv2-SMI::enterprises.32473.8.2.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.32473.8.2.2.1 = STRING: "gstats"
SNMPv2-SMI::enterprises.32473.8.2.3.1 = STRING: "/jffs/memfree.sh"
SNMPv2-SMI::enterprises.32473.8.2.100.1 = INTEGER: 0
SNMPv2-SMI::enterprises.32473.8.2.101.1 = STRING: "69.38"
SNMPv2-SMI::enterprises.32473.8.2.102.1 = INTEGER: 0
SNMPv2-SMI::enterprises.32473.8.2.103.1 = ""

Any idea what I might be doing wrong?
 
Last edited:
Well at the risk of stating the obvious, your script is not producing any output (.101.1).

Two things to check;
1) Is the script running at all?
2) If it is running perhaps the "cat ..." command is hanging/crashing.

I suggest that you test for 2) by replacing the "cat ..." command with "echo 99.9" and see if that gives you any output.
 
Well at the risk of stating the obvious, your script is not producing any output (.101.1).
Yep, that's the problem. :-)

1) Is the script running at all?
It's definitely running. I used logger to prove that memfree.sh starts and finishes.

2) If it is running perhaps the "cat ..." command is hanging/crashing.
Maybe, but it works if I run memfree.sh manually from a shell.

I suggest that you test for 2) by replacing the "cat ..." command with "echo 99.9" and see if that gives you any output.
Already tried that. I see the logger output in the log, but not the echo. However, it works from a shell.

Code:
memfree.sh:
#!/bin/sh
logger "### START ###"
echo xxxxx
logger "### END ###"

Invoked from the Windows client:
c:\usr\bin\snmpwalk.exe -v 2c -c public 10.0.3.1 .1.3.6.1.4.1.32473.8.2

Returns:
SNMPv2-SMI::enterprises.32473.8.2.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.32473.8.2.2.1 = STRING: "memfree"
SNMPv2-SMI::enterprises.32473.8.2.3.1 = STRING: "/jffs/memfree.sh"
SNMPv2-SMI::enterprises.32473.8.2.100.1 = INTEGER: 0
SNMPv2-SMI::enterprises.32473.8.2.102.1 = INTEGER: 0

And in the log:
Jul 24 19:59:27 unknown user.notice root: ### START ###
Jul 24 19:59:27 unknown user.notice root: ### END ###

Invoked from a shell on the router:
memfree.sh

Returns:
xxxxx

And in the log:
Jul 24 20:00:47 unknown user.notice root: ### START ###
Jul 24 20:00:47 unknown user.notice root: ### END ###

I feel like I'm missing something obvious. What do you think?
 
FYI, it doesn't work when I echo a number either. I think the interesting part is that it skips 101.1.
 
Hmm. I can only think that it's a peculiarity of the version of snmpd on the router.

How about trying this in snmpd.conf instead. Although I can't imagine why it would make a difference. :rolleyes:

Code:
exec .1.3.6.1.4.1.32473.8.2 memfree /bin/sh /jffs/memfree.sh
 
Hmm. I can only think that it's a peculiarity of the version of snmpd on the router.

How about trying this in snmpd.conf instead. Although I can't imagine why it would make a difference. :rolleyes:

Code:
exec .1.3.6.1.4.1.32473.8.2 memfree /bin/sh /jffs/memfree.sh

Excellent idea - it worked! It's the exec that fixed it.

Thank you so much! I never would have thought of that.
 
Wow. That's a lucky guess.:D

Was it the exec command vs. sh ? I thought they were meant to be synonymous.

Or was if because of the change from "/jffs/memfree.sh" to "/bin/sh /jffs/memfree.sh"? (Perhaps sysout was getting lost because of the way the shell was being spawned).
 
Maybe lucky, but they were still good leads. It turned out that changing from sh to exec did the trick. Deliberately spawning a shell (/bin/sh) didn't change anything.

I think exec and sh are basically the same, but sh forces a new shell. Exec only spawns a shell if the target is a script. In this case, if one of exec or sh worked, I would expect it to be sh. Either I'm wrong, or the behavior on Tomato is reversed.
 
Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top