SNMP - Is anyone leveraging info via the Simple Network Management Protocol ?
-
Impressive stuff, thanks for sharing @prophead ..
Earlier you mentioned ‘ Edgerouter’ , does that mean you have a Ubiquiti router ? If so would you be able to share the scene Lua for that, as I have a Unfi set up so would love to test that out..
-
-- SNMP BWmon -- read stored in/out values local files = "" local f = io.open("/tmp/INO.txt") if not f then os.execute("touch /tmp/INO.txt") end for line in f:lines() do files = line end f:close() local OINO = files local f = io.open("/tmp/OUTO.txt") if not f then os.execute("touch /tmp/OUTO.txt") end for line in f:lines() do files = line end f:close() if not files then files = "Counter32: (0)" end local OOUTO = files -- parse values local ROINO = string.match(OINO, ".*Counter32: (%d+)") local ROOUTO = string.match(OOUTO, ".*Counter32: (%d+)") -- read snmp os.execute("/usr/bin/snmpget -r 1 -v1 -c PASSWORD 172.16.0.1 iso.3.6.1.2.1.2.2.1.10.4 >/tmp/INO.txt") local f = io.open("/tmp/INO.txt") if not f then return end for line in f:lines() do files = line end f:close() local INO = files --print (INO) files = "" os.execute("/usr/bin/snmpget -r 1 -v1 -c PASSWORD 172.16.0.1 iso.3.6.1.2.1.2.2.1.16.4 >/tmp/OUTO.txt") local f = io.open("/tmp/OUTO.txt") if not f then return end for line in f:lines() do files = line end f:close() local OUTO = files --print (OUTO) --parse local RINO = 0 RINO = string.match(INO, ".*Counter32: (%d+)") local ROUTO = 0 ROUTO = string.match(OUTO, ".*Counter32: (%d+)") --print (RINO) --print (ROUTO) --maths local RINB = 0 RINB = RINO --* 8 local ROINB = 0 ROINB = ROINO --* 8 local ROUTB = 0 ROUTB = ROUTO --* 8 local ROOUTB = 0 ROOUTB = ROOUTO --* 8 --deltas local INt = 0 INt = RINB - ROINB local OUTt = 0 OUTt = ROUTB - ROOUTB local max32 = 4294966864 --debug --luup.log ('RINB ='..RINB..', ROINB ='..ROINB) --luup.log ('ROUTB ='..ROUTB..', ROOUTB ='..ROOUTB) -- handle rotation if RINB < ROINB then INt = max32 - ROINB + RINB end if ROUTB < ROOUTB then OUTt = max32 - ROOUTB + ROUTB end if INt > max32 or INt<0 then INt = max(RINB,ROINB) end if OUTt > max32 or OUTt<0 then OUTt = max(ROUTB,ROOUTB) end --luup.log ('INt ='..INt..', OUTt ='..OUTt) -- 60 is 1 min interval and 1024 makes kBps local kbpsINt = ((INt/60)/1024) local kbpsOUTt = ((OUTt/60)/1024) local total = kbpsINt + kbpsOUTt luup.variable_set("urn:upnp-org:serviceId:altui1", "ComcastKBps", total, 11) luup.variable_set("urn:upnp-org:serviceId:altui1", "ComcastInKBps", kbpsINt, 11) luup.variable_set("urn:upnp-org:serviceId:altui1", "ComcastOutKBps", kbpsOUTt, 11)
-
Quick observation, if I try the following against my UniFi (USG) Router
local command = io.popen("ssh -y -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.144 'snmpget -r 1 -v1 -c public 192.168.102.1 iso.3.6.1.2.1.2.2.1.10.4' 2>&1") local response = command:read("*a") print(response)
it times out..
Timeout: No Response from 192.168.102.1.
Yet if I try this against a UniFi Switch,
local command = io.popen("ssh -y -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.144 'snmpget -r 1 -v1 -c public 192.168.102.7 iso.3.6.1.2.1.2.2.1.10.4' 2>&1") local response = command:read("*a") print(response)
it works fine.
iso.3.6.1.2.1.2.2.1.10.4 = Counter32: 29157590
Hummm..
-
I tried an snmpwalk on the UniFi (USG) Router too,
'snmpwalk -Os -c public -v 1 192.168.102.1' 2>&1
and that timed out..
More digging is needed later, as all seem to have SNMP enabled..
-
@parkerc sounds like a permissions issue. Debug on command line before trying to script. I would also avoid use of the public access to snmp as it’s a potential security issue. I always setup private domain the proceedure differs by manufacturers. You can use snmpwalk for debugging then move to snmpget once you’re ready to drill down. Good luck.
18/18