完成 dp上报和条件检测

This commit is contained in:
Bujue.Win10 2022-02-17 16:20:43 +08:00
parent e8e926759f
commit 158c5dff20
1 changed files with 39 additions and 15 deletions

View File

@ -3,11 +3,11 @@
############################# #############################
# clean data and filter some to rediect to new file # clean data and filter some to rediect to new file
# Author: Liao # Author: Liao
# modify time: 2021/12/15 17:05 (+8:00) # modify time: 2022/2/17 17:05 (+8:00)
############################# #############################
BEGIN{ BEGIN{
filePath = "/data/log_dir/mySimpleLog" # filePath = "/data/log_dir/mySimpleLog"
# system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path) # system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path)
@ -24,17 +24,45 @@ BEGIN{
$0~/ dp rept_type:[0-9]+, data:/ { $0~/ dp rept_type:[0-9]+, data:/ {
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; 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,/\{.+\}/) ? substr($0,RSTART,RLENGTH):null; adps = match($0,/\{.+\}/) ? substr($0,RSTART,RLENGTH):null;
# print "atime:"atime,"adps:"adps
newjson = "{ \"time\":"atime", \"event\":\"dp report\", \"dps\":"adps"}" aLogJson = "{ \"time\":"atime", \"event\":\"dp report\", \"dps\":"adps"}"
system("echo -e '"newjson"' >> /data/log_dir/mySimpleLog") # log2file(aLogJson)
} }
$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) : $0;
devMac = match($0,/rev id:\w+/) ? substr(substr($0,RSTART,RLENGTH),8) : null
# print $0
if((getline conditionLine) > 0){
isCondition = match(conditionLine,/(no id match|no dp match)/) ? "false" : match(conditionLine,/dp [0-9]+ match/) ? "true" : "unkown"
# print conditionLine
# print "isCondition:"isCondition
condition = "\"isCondition\":"isCondition
if (isCondition=="true"){
# conditionDp = match(conditionLine,/dp [0-9]+ match/) ? substr(conditionLine,RSTART,RLENGTH) : ""
conditionDp = match(conditionLine,/\] dp [0-9]+ match/) ? substr(substr(conditionLine,RSTART,RLENGTH),6,RLENGTH-11) : ""
condition = condition",\"conditionDp\":"conditionDp
}
}else{
print "no more line"
}
aLogJson = "{ \"time\":"atime", \"event\":\"linkage recv dp\", \"dps\":"adps",\"devMac\":\""devMac"\","condition"}"
log2file(aLogJson)
}
# $0~/dp [0-9]+ match/{ # $0~/dp [0-9]+ match/{
# } # }
# $0~/condition set is ok,then execute action set\./ {
# aruleid = substr(matchRet(/scene:[0-9a-zA-Z]+\b/),7) $0~/condition set is ok,then execute action set\./ {
# print aruleid # 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", \"ruleid\":\""aruleid"\",\"triggerNow\":\"true\"}")
}
END{ END{
@ -49,10 +77,6 @@ function matchRet(reg ,RSTART,RLENGTH){
} }
} }
function maker_Json(){ function log2file(logJson){
return "{ \"time\":"matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/)", \"event\":"matchRet()", \"value\":"matchRet()", \"dps\":"adps"}" system("echo -e '"logJson"' >> /data/log_dir/mySimpleLog")
}
function write2file(maker_Json){
system("echo "maker_Json" >> $filePath")
} }