[英]How can I store this log data in database
I have a log file
from firewall, and I want to store it in mysql
database using php
, I have used the same key for database, I want to separate
the log data in array key=value
format and again there is space
between each key values, and there are some countries
which contain spaces between the coutry name.我有一个来自防火墙的log file
,我想使用php
将它存储在mysql
数据库中,我对数据库使用了相同的密钥,我想以array key=value
格式separate
日志数据,并且每个键之间再次有space
值,并且有些countries
在国家/地区名称之间包含空格。 So how can I complete my task.那么我怎样才能完成我的任务。 And for the idea here you can see the log file:对于这里的想法,您可以查看日志文件:
date=2016-04-11 time=11:26:29 logid=0000000013 type=traffic
subtype=forward level=notice vd=root srcip=10.10.24.232 srcport=35321
srcintf="port2" dstip=173.252.74.22 dstport=443 dstintf="wan1"
poluuid=426a22f0-b2d8-51e5-4e06-b3d158ed335f sessionid=11469008
proto=6 action=deny policyid=33 dstcountry="United States"
srccountry="Reserved" trandisp=snat transip=202.166.220.127
transport=35321 service="HTTPS" appid=15832 app="Facebook"
appcat="Social.Media" apprisk=medium applist="GEN-ACC-FBBLK"
appact=drop-session duration=22 sentbyte=120 rcvdbyte=60 sentpkt=2
utmaction=block countapp=1 utmref=62972-2591658 date=2016-04-11
time=11:26:29 logid=0000000013 type=traffic subtype=forward
level=notice vd=root srcip=10.10.37.60 srcport=43857 srcintf="port2"
dstip=202.166.193.187 dstport=443 dstintf="wan1"
poluuid=426a22f0-b2d8-51e5-4e06-b3d158ed335f sessionid=11373387
proto=6 action=close policyid=33 dstcountry="Nepal"
srccountry="Reserved" trandisp=snat transip=202.166.220.127
transport=43857 service="HTTPS" appid=41542 app="SSL_TLSv1.0"
appcat="Network.Service" apprisk=medium applist="GEN-ACC-FBBLK"
appact=detected duration=424 sentbyte=1320 rcvdbyte=1582 sentpkt=10
rcvdpkt=16 utmaction=allow countapp=2 utmref=62972-2591632
Finally I can correct it myself, I hope it will help to others too:终于可以自己改正了,希望对大家也有帮助:
$str = file_get_contents($_FILES["file"]["tmp_name"]);
$str1 = str_replace("\"", "", ($str) );
$vals=split('date=', $str1);
array_shift($vals);
$finalArray = array();
$j = 0;
foreach($vals as $v){
$finalArray[$j]["date"] = substr($v, 0, 10);
//var_dump($v);
$tempString = substr($v, 11);
$tempArr = explode(" ", $tempString);
$prevTemp = "";
foreach($tempArr as $i){
$tmp = explode("=",$i);
if(!isset($tmp[1])){
$finalArray[$j][$prevTemp] = $finalArray[$j][$prevTemp]." ".$i;
}
else{
$finalArray[$j][$tmp[0]] = isset($tmp[1]) ? $tmp[1]: '';
$prevTemp = $tmp[0];
}
}
$j++;
}
//var_dump($finalArray);
//die();
$totalQuery = '';
foreach($finalArray as $val){
if(is_array($val)){
$queryText = 'INSERT INTO `intrulog` SET';
$i = 0;
foreach($val as $k=>$v){
if(isset($v) && !empty($v)){
if($i)
$queryText .= ',';
$queryText .= " `{$k}` = '{$v}' ";
$i++;
}
}
$queryText .= ";<br>";
$totalQuery .= $queryText;
}
}
//echo $queryText;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.