AnsweredAssumed Answered

Lua help

Question asked by ntimm on Apr 20, 2010
Latest reply on Apr 20, 2010 by ntimm

I am in the process of converting my python script to lua and am able to get the values I need but as of this time it's killing me to grab the oid value and split it.  Below is some code and then the output.

I have tried multiple ways and splits but can't get the values I need.  Maybe I am not doing it the correct way.  Below is the script along with 2 different output of the snmp.walk.

 

The string I am string to grab and splic is the ucd value splitting off is the ucd .iso.3.6.1.4.1.14179.2.1.4.1.3. I just need the last few values of that oid.

 

 

local cfg = probe.config("wlctest.cfg")

-- Variables
sysname = ".1.3.6.1.2.1.1.6.0"
rootoid = ".1.3.6.1.4.1.14179"
macoid = ".1.3.6.1.4.1.14179.2.1.4.1.1" --client mac
ipaddoid =  '.1.3.6.1.4.1.14179.2.1.4.1.2' -- Client IP
nameoid =  '.1.3.6.1.4.1.14179.2.1.4.1.3' -- Client Name
apmacoid =  '.1.3.6.1.4.1.14179.2.1.4.1.4' -- AP mac
ssidoid =  '.1.3.6.1.4.1.14179.2.1.4.1.7' -- SSID that client is connected to
statusoid =  '.1.3.6.1.4.1.14179.2.1.4.1.9' -- INTEGER {idle(0), aaaPending(1), authenticated(2), associated(3), powersave(4), disassociated(5), tobedeleted(6), probing(7), blacklisted(8)}
protooid =  '.1.3.6.1.4.1.14179.2.1.4.1.25' -- Client Protocol A,B,G
policyoid =  '.1.3.6.1.4.1.14179.2.1.4.1.30' -- Client policy INTEGER {dot1x(0), wpa1(1), wpa2(2), wpa2vff(3), notavailable(4), unknown(5)}
encoid =  '.1.3.6.1.4.1.14179.2.1.4.1.30' -- Client INTEGER {ccmpAes(0), tkipMic(1), wep40(2), wep104(3), wep128(4), none(5), notavailable(6), unknown(7)}
rssioid =  '.1.3.6.1.4.1.14179.2.1.6.1.1' -- Client RSSI
brecoid =  '.1.3.6.1.4.1.14179.2.1.6.1.2' -- Client bytes Rec
bsentoid =  '.1.3.6.1.4.1.14179.2.1.6.1.3' -- Client bytes sent
policyerroid =  '.1.3.6.1.4.1.14179.2.1.6.1.4' -- Client bytes sent
snroid =  '.1.3.6.1.4.1.14179.2.1.6.1.26' -- Client SNR
txretoid = '.1.3.6.1.4.1.14179.2.1.21.1.2' -- TX Retries

-- Historic OIDs
hrssi = '.1.3.6.1.4.1.14179.2.1.11.1.5'  -- Historic RSSI
hap = '.1.3.6.1.4.1.14179.2.1.11.1.4' -- Historing Ap name that client was connected to.
apnameoid = '.1.3.6.1.4.1.14179.2.1.11.1.4' -- Historic ap root
apnametoid = '.48.55.166.74.223.112.0.0' -- End of historic ap last value

function protocol(protoval)
 if protoval == 1 then
  proto = 'dot11a'
 elseif protoval == 2 then
  proto = 'dot11b'
 elseif protoval == 3 then
  proto = 'dot11g'
 elseif protoval == 4 then
  proto = 'mobile'
 else
  proto = 'unknown'
 end
 return proto
end

nimbus.log(0,"------ Starting -------")

comstr = "m5nc0mm"

if cfg ~= nil and cfg["/setup"] then
  printf("Loglevel = %s",cfg["/setup"].loglevel)
  
  prf=cfg["/profiles"]
    for host,target in pairs (prf) do
        printf ("Running script for hostname: %s  ipaddress: %s", host,target)
     h = snmp.create (2,target,comstr)
    end
end

printf ("----[ Do a snmpwalk]----")

out = snmp.walk(h,rootoid..".2.1.4.1.3",rootoid..".2.1.4.1.3")


if out ~= nil then
 if out.numoids > 0 then
  for i,oid in pairs(out.oids) do
   printf("k: %s",i)
   for key,value in pairs(oid) do
    printf ("  %s: %s",key,value)
   end
  end   
 end
else
 printf("no data..."); 
end

 

 

out = snmp.walk(h,rootoid..".2.1.4.1.3",rootoid..".2.1.4.1.3")

idx = 0
while out ~= nil do
 for i=0,out.numoids-1 do
  printf ("%d oid: %s, type: %s", idx, out.oids[tostring(i)].oid, out.oids[tostring(i)].type)
  id = out.oids[tostring(i)].oid
  print (id)
  idx=idx+1
  hid = split(id,".1.3.6.1.4.1.14179.2.1.4.1.3")
  print (hid[2])
 end
 
 if out.done == 1 then break end
 out = snmp.walk(h,out.lastoid,".1.3.6.1.4.1.14179.2.1.4.1.3")
end
snmp.delete(h)

 

 

----------Output------

k: 12
  type: OCTET STRING
  ucd: .iso.3.6.1.4.1.14179.2.1.4.1.3.0.29.217.74.7.157
  oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.29.217.74.7.157
  value: "MSNCOMM2\\lmainero"
  variable: "MSNCOMM2\\lmainero"
  itype: 4
k: 22
  type: OCTET STRING
  ucd: .iso.3.6.1.4.1.14179.2.1.4.1.3.0.31.225.69.51.192
  oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.31.225.69.51.192
  value: "MSNCOMM2\\rconybear"
  variable: "MSNCOMM2\\rconybear"
  itype: 4
k: 10
  type: OCTET STRING
  ucd: .iso.3.6.1.4.1.14179.2.1.4.1.3.0.29.217.74.7.4
  oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.29.217.74.7.4
  value: "MSNCOMM2\\mspiegelhalter"
  variable: "MSNCOMM2\\mspiegelhalter"
  itype: 4

 

---- Output 2 ---------

 

 

31 oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.38.8.227.226.192, type: OCTET STRING
.1.3.6.1.4.1.14179.2.1.4.1.3.0.38.8.227.226.192
8
32 oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.38.8.244.114.209, type: OCTET STRING
.1.3.6.1.4.1.14179.2.1.4.1.3.0.38.8.244.114.209
8
33 oid: .1.3.6.1.4.1.14179.2.1.4.1.3.0.192.27.13.254.116, type: OCTET STRING
.1.3.6.1.4.1.14179.2.1.4.1.3.0.192.27.13.254.116
5
34 oid: .1.3.6.1.4.1.14179.2.1.4.1.3.124.109.98.192.108.16, type: OCTET STRING
.1.3.6.1.4.1.14179.2.1.4.1.3.124.109.98.192.108.16
8
35 oid: .1.3.6.1.4.1.14179.2.1.4.1.3.144.132.13.121.91.2, type: OCTET STRING
.1.3.6.1.4.1.14179.2.1.4.1.3.144.132.13.121.91.2

Outcomes