What will be the approach to show some hardware data in SNMP & LUCI

Hi

I do have several ZyXEL devices with OpenWRT on them.
All of them give a result like this

serialnum=S122L44080XXX countrycode=756 eth0mac=B0:B2:DC:AA:AA:AA wifi0mac=B0:B2:DC:BB:BB:BB wifi1mac=B0:B2:DC:CC:CC:CC

when I parse the mtdblok6 with a grep for serialnum

cat /dev/mtdblock6 | grep "serialnum"

what will be the way to display at least the serial number ( country code nice to have ) in SNMP AND/OR LUCI

Does OpenWRT has a predefined variable to be populated with a script at boot ?

Create a script to extract the desired values.
Add it in snmpd.conf:
pass .1.3.6.1.2.1.25.1.8 /bin/sh /root/bin/your_script.sh

I am not able to do it

I don't understand why the /etc/snmp/snmpd.conf is rewritten with some "defaults" each time the service is restarted

I've created a script
Tried to put it both in /root/bin or /usr/local/bin
Made it executable
From command line is working fine and is returning only the serial

I am editing in console the snmpd.conf and adding the line
I am checking it regularly with cat /etc/snmp/snmpd.conf
All seems ok
UNTIL
When I restart the service ( even through reboot ) , the line "disappears" from the config.

all it remains is

root@NWA1123-NI:~# cat /etc/snmp/snmpd.conf 
agentaddress UDP:161,UDP6:161
master agentx
agentXSocket /var/run/agentx.sock
sysLocation ch;bl;town;u
sysContact mymail@gmail.com
sysName NWA1123-NI
com2sec ro default mymyread
com2sec rw localhost mymyrwrw
com2sec6 ro default mymyread
com2sec6 rw localhost mymyrwrw
group public v1 ro
group public v2c ro
group public usm ro
group private v1 rw
group private v2c rw
group private usm rw
view all included .1 
access public "" any noauth exact all none none
access private "" any noauth exact all all all
exec  filedescriptors /bin/cat /proc/sys/fs/file-nr
engineIDType 3
engineIDNic eth0

tried to put the line to pass the OID last, first,... in the middle

I need to mention that the snmpd.conf is generated by LUCI SNMP module.

Should I try to remove the LUCI SNMP module and do it manually?
Should I try to modify the LUCI in such a way it adds some custom snmpd config file?

Add this in /etc/config/snmpd

config pass
        option name 'test'
        option prog '/bin/sh /root/bin/your_script.sh'
        option miboid '.1.3.6.1.2.1.25.1.8'
2 Likes

Success
Thanks man

2 Likes

for those who wish to have the serial for ZyXEL devices this is the fastest way I've been able to extract it with a simple script

#!/bin/sh

cat /dev/mtdblock6 | grep "serialnum" | awk '{print$1}' |  sed 's/serialnum=//g'


2 Likes

Is working for Raspberry Pi, too.

like this

config extend
        option name 'serial-number'
        option prog '/bin/cat /sys/firmware/devicetree/base/serial-number'
        option miboid '.1.3.6.1.2.1.25.1.8'

I have ended up to use extend on both ZyXEL devices and Raspberry Pi with "serial-number"
In this way all OpenWRT devices I use will have the same OID for serial number.
Easy to create a template for monitoring / inventory.

For ZyXEL I use

config extend
        option name 'serial-number'
        option prog '/bin/sh /usr/local/bin/find_serial.sh'
        option miboid '.1.3.6.1.2.1.25.1.8

with the script from previous post

2 Likes

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