要不要再翻翻文档呢?

logstash6.x: undefined method '*' for nil:NilClass

Logstash | 作者 erha_erha | 发布于2018年06月27日 | 阅读数:3616

filter中用的是ruby来处理的,但是总会报问题中的error,之前在5.3中跑的很正常
已邀请:

erha_erha - 90后程序员

赞同来自:

# -*- coding: UTF-8 -*-
sql="2018-05-01 12:30:39 insert into web_browsing_201805 (file_path,projCode,web_sit,test_description,photoreceptor,wifi_list,upper_imei,operator,file_index,WIFI_channel,reference,province,operator_manual,phone_manufacturer,net_name,model,signal_strength,wifi_connect_rate,longitude,test_place,test_status,logversion,lac_tac,WIFICochannelHotNum,eighty_loading,haschange,eci1,gps,eighty_rate,sinr,UID,WIFI_HotNum,cid_pci,service_status,title_delay,bluetothDeviceName,success_counts,phone_number,success_rate,resource_count,WIFIProxy,service_ip,signal_strength2,city,bssid,probeID,latitude,signal_strength1,testType,wifi_ss,city_code_path,service_Time,sinr1,detailreport,connect_operator,android_ios,firstpack_delay,net_type1,sinr2,net_type2,openBroadband_phone,WIFI_EncryptionMethod,cei1,bandwidth,net_type,cid_pci1,ip_address,cid_pci2,test_location_manual,ninety_loading,WIFISameFrequencyHotNum,device_org,test_location,full_complete,lac_tac1,service_url,lac_tac2,terminal_mac,electricityConsumption,province_code_path,imei,cpu_consume,time,memory_consume,test_scene ) values ('/opt/OTS_NEW/mnt/uploadfile/ZIRANWEI_REPORTS_31/public/700021/11/0100/1055/201805010000/browse/dd55e8dfaa9ee34436e3222679481585/SPafe658d48a87841528d95c9dc1931f03_02001.F23736_0-2018_05_01_00_13_36_838.summary.csv','700021','https://www.apple.com/cn','20','--','--','e5db7b467fa261791ea5bc272801004e00e953f1','','dd55e8dfaa9ee34436e3222679481585|SPafe658d48a87841528d95c9dc1931f03_02001.F23736_0-2018_05_01_00_13_36_838.summary.csv_4','--','2849.92','北京','其他','Apple','@PHICOMM_28','iPhone 7(iPhone9,1)','--','--',116.42373368218254,'--','200','3.3.1','','--','','0','','116.411062E 39.894457N','','--','dd55e8dfaa9ee34436e3222679481585','--','','200','3927.131057','--',1,'13911133552','100%','46','--','210.192.117.229','--','北京','cc:81:da:39:b2:38','1055',39.902077464060106,'0','browse','--','0100','--','--','','-','ios','290.01','LTE','--','--','--','--','','20','WIFI','','106.2.231.20','','太华公寓','3908.02','--','','','3927.13','','https://www.apple.com/cn','','--','--','11','','43.08','1525104796005','21.55','--' )
"
mesg = sql.split("values")

keyss = mesg[0]

idx = keyss.index('i')
log_time = keyss[0..idx-2]
puts log_time.split(" ")[1][0..1]
require 'time'
#puts Time.parse(log_time)
lid = keyss.index('(')
rid = keyss.rindex(')')
keys = keyss[lid+1..rid-1].split(',')
valuess = mesg[1]
lidv = valuess.index('(')
ridv = valuess.rindex(')')
sqlStr = valuess[lidv+1..ridv-1]
values = Array.new
t = 0
index = 0
tt = ''
for i in 0..sqlStr.length-1
t1 = sqlStr[i]
if t1 == '\''
t = t + 1
end
if t1 == ',' && t % 2 == 0
values[index] = tt
index = index + 1
tt = ''
t = 0
next
end
tt = tt + t1
if i == sqlStr.length - 1
values[index] = tt
end
end
indexK = keys.size
indexV = values.size

for i in 0..keys.size

if keys[i] == 'time' then
puts values[i]
end
if keys[i] == 'province' then
puts 'province'+values[i]
end
if keys[i] == 'city' then
puts values[i]
end
if keys[i] == 'phone_number' then
puts values[i]
end
if keys[i] == 'longitude' then
puts values[i]
end
if keys[i] == 'latitude' then
puts values[i]
end
if keys[i] == 'test_place' then
puts values[i]
end
if keys[i] == 'connect_operator' then
puts 'connect_operator'+values[i]
end
if keys[i] == 'signal_strength' then
signal_strength = values[i].gsub("'","")
puts signal_strength.to_f
end
if keys[i] == 'net_type' then
puts 'net_type'+values[i]
end
if keys[i] == 'bandwidth' then
puts 'bandwidth'+values[i]
end
if keys[i] == 'success_rate' then
success_rate = values[i].gsub("'","")
puts success_rate.to_f
end
if keys[i] == 'ninety_loading' then
ninety_loading= values[i].gsub("'","")
puts ninety_loading.to_f

end


end



 

erha_erha - 90后程序员

赞同来自:

​ 上面代码就是ruby code中的内容了 总是报ruby exception occurred:underfined method 'gsub' for nil:nilclass
 

要回复问题请先登录注册