This commit is contained in:
Bujue.Win10 2022-02-18 16:45:09 +08:00
parent dd822625d6
commit c7bb0b9df9
4 changed files with 16 additions and 32 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
mySimpleLog_*
mySimpleLog*

View File

@ -2,24 +2,18 @@
#############################
# clean data and filter some to rediect to new file
# env: rlx linux with origin-awk
# Author: Liao
# modify time: 2022/2/17 17:05 (+8:00)
# modify time: 2022/2/18 16:05 (+8:00)
#############################
BEGIN{
fileSize = 1024*1
uploadCount = 0
# filePath = "/data/log_dir/mySimpleLog"
# system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path)
#dp_recv_from_device = @/ dp rept_type:[0-9]+, data:/
#dp_is_condition = @/dp [0-9]+ match/
#dp_not_condition = @/no id match/
#pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/
#connection_check_ok = @/condition set is ok,then execute action set./
# Get form OS
log2file("{\"event\":\"gateway reboot\"}")
log2file("{ \"event\":\"gateway startup\"}")
}
@ -33,14 +27,14 @@ $0~/ dp rept_type:[0-9]+, data:/ {
$0~/rev id:\w+ cmd:\{.*\} type:0/ {
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
adps = match($0,/cmd:\{.+\} /) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-5) : "unkown";
adps = match($0,/cmd:\{.+\} /) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-5) : "\"unkown\"";
devMac = match($0,/rev id:\w+/) ? substr(substr($0,RSTART,RLENGTH),8) : null
if((getline conditionLine) > 0){
isCondition = match(conditionLine,/(no id match|no dp match)/) ? "false" : match(conditionLine,/dp [0-9]+ match/) ? "true" : "unkown"
isCondition = match(conditionLine,/(no id match|no dp match)/) ? "false" : match(conditionLine,/dp [0-9]+ match/) ? "true" : "\"unkown\""
condition = "\"isCondition\":"isCondition
if (isCondition=="true"){
conditionDp = match(conditionLine,/\] dp [0-9]+ match/) ? substr(substr(conditionLine,RSTART,RLENGTH),6,RLENGTH-11) : "unkown"
conditionDp = match(conditionLine,/\] dp [0-9]+ match/) ? substr(substr(conditionLine,RSTART,RLENGTH),6,RLENGTH-11) : "\"unkown\""
condition = condition",\"conditionDp\":"conditionDp
}
}else{
@ -55,12 +49,12 @@ $0~/condition set is ok,then execute action set\./ {
# print $0
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
aruleid = match($0,/scene:\w+,/) ? substr(substr($0,RSTART,RLENGTH),7,RLENGTH-7) : "false"
log2file("{ \"time\":"atime", \"event\":\"trigger\", \"ruleid\":\""aruleid"\",\"triggerNow\":\"true\"}")
log2file("{ \"time\":"atime", \"event\":\"trigger\", \"ruleid\":\""aruleid"\",\"triggerNow\":true}")
}
$0~/action<[0-9]+> is dp cmd:/ {
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
adps = match($0,/cmd:\{.+\}$/) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-4) : "unkown";
adps = match($0,/cmd:\{\".+\}/) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-4) : ""$0;
aLogJson = "{ \"time\":"atime", \"event\":\"action\", \"cmd\":"adps"}"
log2file(aLogJson)
@ -68,16 +62,8 @@ $0~/action<[0-9]+> is dp cmd:/ {
END{
}
function matchRet(reg ,RSTART,RLENGTH){
#print reg
if(match($0,$reg)){
return substr($0,RSTART,RLENGTH)
}else{
return "Nothing Matched"
}
splitAndUpload()
print "upload "uploadCount" count"
}
function log2file(logJson){
@ -85,21 +71,19 @@ function log2file(logJson){
}
function checkFileSize(){
# system("ls -l /data/log_dir/mySimpleLog | awk '{ print $5 }' | cat > /tmp/bujueFileSize")
checkState = system("ls -l /data/log_dir/mySimpleLog | awk '{ if($5 >"fileSize"){exit 0}else{exit 1} }'")
print checkState
if(!checkState){
print "uploading..."
splitAndUpload()
# print "uploaded"
}
}
function splitAndUpload(){
newFileName = "mySimpleLog_"systime()
print "uploading..."
ret = system("mv /data/log_dir/mySimpleLog /data/log_dir/"newFileName" && cd /data/log_dir/ && tftp 192.168.1.5 -p -l "newFileName" && rm "newFileName)
if(!ret){
print "upload success!"
uploadCount++
}else{
print "upload fail!"
}

View File

@ -3,4 +3,4 @@
cd /tmp && tftp 192.168.1.5 -g -l logDataClean.awk
tail -f /tmp/tuya.log | awk -f logDataClean.awk &
tail -f /tmp/tuya.log | awk -f logDataClean.awk > /dev/null &

BIN
tftpd64.exe Normal file

Binary file not shown.