| | |
| | | log "github.com/long/test/log" |
| | | ) |
| | | |
| | | func GetEsDataReq(url string, parama string, isSource bool) (error, map[string]interface{}) { |
| | | func GetEsDataReq(url string, parama string, picurl string, isSource bool) (error, map[string]interface{}) { |
| | | //log.Log.Infoln("es 查询请求路径" + url) // 配置信息 获取 |
| | | req, err := http.NewRequest("POST", url, strings.NewReader(parama)) |
| | | |
| | |
| | | } |
| | | |
| | | source["id"] = value.(map[string]interface{})["_id"] |
| | | |
| | | sdkType := source["sdkType"] |
| | | if sdkType != nil { |
| | | sdk, err := strconv.Atoi(sdkType.(string)) |
| | |
| | | source["sdkType"] = sdkTypeToValue(sdk) |
| | | } |
| | | |
| | | pmax, exist := source["picMaxUrl"].(string) |
| | | //fmt.Println("picMaxUrl: ",pmax) |
| | | if !exist { |
| | | return errors.New("picMaxurl is not string"), nil |
| | | } |
| | | |
| | | if !strings.HasPrefix(pmax, "http") { |
| | | source["picMaxUrl"] = picurl + pmax |
| | | |
| | | } |
| | | |
| | | psm, exist := source["picSmUrl"].(string) |
| | | if !exist { |
| | | return errors.New("picSmUrl is not string"), nil |
| | | } |
| | | //fmt.Println("picSmUrl: ",psm) |
| | | if !strings.HasPrefix(psm, "http") { |
| | | source["picSmUrl"] = picurl + psm |
| | | } |
| | | //videoUrl := getVideoUrl(source) |
| | | source["videoNum"] = getVideoUrl(source) |
| | | |
| | |
| | | picDte := source["picDate"].(string)//抓拍日期 |
| | | cameraId := source["videoReqNum"].(string)//摄像机id |
| | | indeviceId := source["indeviceid"].(string)//分析设备id |
| | | deviceMap := make(map[string]string,0) |
| | | deviceMap["DSVAD010120181119"] = "http://172.17.50.241:11111/getRecordVideoPath" |
| | | deviceMap["DSVAD010220181119"] = "http://172.17.50.242:11111/getRecordVideoPath" |
| | | deviceMap["DSVAD010320181119"] = "http://172.17.50.243:11111/getRecordVideoPath" |
| | | deviceMap["DSVAD010420181119"] = "http://172.17.50.244:11111/getRecordVideoPath" |
| | | |
| | | var deviceMap map[string]string |
| | | deviceMap["DSVAD010120181119"] = "http://58.118.225.79:41241/ManCarAnaly/perVideoPic/uploadRtnVideo" |
| | | deviceMap["DSVAD010220181119"] = "http://58.118.225.79:41242/ManCarAnaly/perVideoPic/uploadRtnVideo" |
| | | deviceMap["DSVAD010320181119"] = "http://58.118.225.79:41243/ManCarAnaly/perVideoPic/uploadRtnVideo" |
| | | deviceMap["DSVAD010420181119"] = "http://58.118.225.79:41244/ManCarAnaly/perVideoPic/uploadRtnVideo" |
| | | ngxMap := make(map[string]string,0) |
| | | ngxMap["DSVAD010120181119"] = "http://58.118.225.79:44180/videosource" |
| | | ngxMap["DSVAD010220181119"] = "http://58.118.225.79:44280/videosource" |
| | | ngxMap["DSVAD010320181119"] = "http://58.118.225.79:44380/videosource" |
| | | ngxMap["DSVAD010420181119"] = "http://58.118.225.79:44480/videosource" |
| | | |
| | | |
| | | reqUrl := deviceMap[indeviceId] |
| | | var paramMap map[string]interface{} |
| | | paramMap := make(map[string]interface{},0) |
| | | paramMap["imgKey"] = imgKey |
| | | paramMap["picDate"] = picDte |
| | | paramMap["videoPath"] = cameraId |
| | | paramMap["videoNum"] = cameraId |
| | | |
| | | respBytes, err := doPostRequest(reqUrl, "application/x-www-form-urlencoded", paramMap, nil, nil) |
| | | respBytes, err := doPostRequest(reqUrl, "application/json", paramMap, nil, nil) |
| | | if err !=nil{ |
| | | return "" |
| | | } |
| | |
| | | if err !=nil { |
| | | return "" |
| | | } |
| | | return resp.VideoPath |
| | | filePath := resp.FilePath |
| | | |
| | | if !strings.Contains(filePath, "/cut"){ |
| | | return "" |
| | | } else { |
| | | strArr := strings.Split(filePath, "/cut") |
| | | ngxUrl := ngxMap[indeviceId] |
| | | if ngxUrl !="" && len(strArr) >0 { |
| | | return ngxUrl + strArr[1] |
| | | } |
| | | } |
| | | |
| | | return "" |
| | | } |
| | | |
| | | type RespVideo struct{ |
| | | Code int32 `json:"code"` |
| | | ErrorStr string `json:"errorStr"` |
| | | Msg string `json:"msg"` |
| | | Resp interface{} |
| | | Status string `json:"status"` |
| | | VideoPath string `json:"videoPath"` |
| | | FilePath string `json:"file_path"` |
| | | } |
| | | |
| | | |
| | | func doPostRequest(url string, contentType string, body map[string]interface{}, params map[string]string, headers map[string]string) ([]byte, error) { |
| | | var resultBytes []byte |
| | | var bodyJson []byte |
| | |
| | | return value[i-1] |
| | | } |
| | | |
| | | func PostAction(sec int, Eurl string) []byte { |
| | | func PostAction(sec int, Eurl string, picurl string) []byte { |
| | | index := "videopersons,personaction" |
| | | url := fmt.Sprintf("%s%s%s", Eurl, index, "/_search") |
| | | |
| | | seccond := strconv.Itoa(sec) |
| | | |
| | | prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"personIsHub\":\"1\"}},{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + seccond + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + |
| | | "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + |
| | | "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"imgKey\",\"sdkType\",\"ageDescription\",\"indeviceid\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + |
| | | "}" |
| | | err, tokenRes := GetEsDataReq(url, prama, picurl, true) |
| | | |
| | | err, tokenRes := GetEsDataReq(url, prama, true) |
| | | if err != nil { |
| | | log.Log.Errorln(err) |
| | | return nil |
| | |
| | | return Log |
| | | } |
| | | |
| | | infopath := "log/log_record/info.log" |
| | | infopath := "logs/info.log" |
| | | infowriter, _ := rotatelogs.New( |
| | | infopath+".%Y%m%d%H%M", |
| | | rotatelogs.WithLinkName(infopath), |
| | |
| | | rotatelogs.WithRotationTime(24*time.Hour), |
| | | ) |
| | | |
| | | errorpath := "log/log_record/error.log" |
| | | errorpath := "logs/error.log" |
| | | errorwriter, _ := rotatelogs.New( |
| | | errorpath+".%Y%m%d%H%M", |
| | | rotatelogs.WithLinkName(errorpath), |
New file |
| | |
| | | logs/error.log.201905280000 |
New file |
| | |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:40660 close","time":"2019-05-27T17:34:24+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55980 close","time":"2019-05-27T17:36:40+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55984 close","time":"2019-05-27T17:36:52+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:40664 close","time":"2019-05-27T17:36:53+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55988 close","time":"2019-05-27T17:37:05+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55990 close","time":"2019-05-27T17:37:17+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55992 close","time":"2019-05-27T17:37:29+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55994 close","time":"2019-05-27T17:37:41+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:55996 close","time":"2019-05-27T17:37:48+08:00"} |
| | | {"level":"error","msg":"read tcp 192.168.1.124:6006-\u003e192.168.1.109:40720: read: connection reset by peer remoteAddr 192.168.1.109:40720 close","time":"2019-05-27T17:38:00+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:56016 close","time":"2019-05-27T17:38:51+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:40722 close","time":"2019-05-27T17:38:56+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.103:56020 close","time":"2019-05-27T17:39:13+08:00"} |
New file |
| | |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:46082 close","time":"2019-05-28T09:56:18+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:46086 close","time":"2019-05-28T09:58:22+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:42530 close","time":"2019-05-28T10:50:35+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:43806 close","time":"2019-05-28T11:49:25+08:00"} |
| | | {"level":"error","msg":"EOF remoteAddr 192.168.1.109:45052 close","time":"2019-05-28T11:58:15+08:00"} |
| | |
| | | |
| | | import ( |
| | | "flag" |
| | | "fmt" |
| | | "net" |
| | | "strconv" |
| | | "time" |
| | |
| | | log "github.com/long/test/log" |
| | | ) |
| | | |
| | | var addr = flag.String("addr", "192.168.1.124", "The address to listen to;") |
| | | var addr = flag.String("addr", "0.0.0.0", "The address to listen to;") |
| | | var Eurl = flag.String("eurl", "http://192.168.1.182:9200/", "The port to listen on; ") |
| | | var Picurl = flag.String("picurl", "http://58.118.225.79:41242/", "picture url ") |
| | | |
| | | var port = flag.Int("port", 6000, "The port to listen on; ") |
| | | var sec = flag.Int("sec", 10, "the second for query data. ") |
| | |
| | | func main() { |
| | | flag.Parse() |
| | | |
| | | log.Log.Infoln("starting server...") |
| | | |
| | | fmt.Println(*port) |
| | | src := *addr + ":" + strconv.Itoa(*port) |
| | | listener, err := net.Listen("tcp", src) |
| | | if err != nil { |
| | |
| | | } |
| | | log.Log.Infof("Listening on %s.\n", src) |
| | | |
| | | fmt.Println("starting server success.") |
| | | defer listener.Close() |
| | | |
| | | connArr:=make([]net.Conn,0) |
| | | |
| | | for { |
| | | conn, err := listener.Accept() |
| | | conn, err := listener.Accept()// |
| | | connArr = append(connArr,conn) |
| | | if err != nil { |
| | | log.Log.Errorf("some connecion error: %s\n", err) |
| | | } |
| | | go handleConnection(conn) |
| | | go handleConnection(conn,connArr) |
| | | } |
| | | } |
| | | |
| | | func handleConnection(conn net.Conn) { |
| | | func handleConnection(conn net.Conn, connArr []net.Conn) { |
| | | remoteAddr := conn.RemoteAddr().String() |
| | | log.Log.Infoln("Client connected from ", remoteAddr) |
| | | |
| | |
| | | for { |
| | | select { |
| | | case <-tick.C: |
| | | handleMessage(conn) |
| | | handleMessage(conn, connArr) |
| | | case err := <-ech: |
| | | log.Log.Errorln(err, "remoteAddr ", remoteAddr, " close") |
| | | conn.Close() |
| | | break |
| | | } |
| | | } |
| | |
| | | log.Log.Infoln("Client at " + remoteAddr + " disconnected.") |
| | | } |
| | | |
| | | func handleMessage(conn net.Conn) { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl) |
| | | func handleMessage(conn net.Conn, connArr []net.Conn) { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl) |
| | | if jsonstring == nil { |
| | | log.Log.Infoln("the data is nil") |
| | | return |
| | | } |
| | | jsonstring = append(jsonstring, []byte("\000")...) |
| | | log.Log.Infoln("jsonstring len: ", len(jsonstring), "\000 data: ", len("\000")) |
| | | conn.Write(jsonstring) |
| | | _, err := conn.Write(jsonstring) |
| | | if err !=nil{ |
| | | fmt.Println("conn: ",conn) |
| | | log.Log.Errorln(err) |
| | | conn.Close() |
| | | index :=0 |
| | | for ;index < len(connArr); { |
| | | if connArr[index] == conn{ |
| | | connArr = append(connArr[:index],connArr[index+1:]...) |
| | | continue |
| | | } |
| | | index++ |
| | | } |
| | | fmt.Println("connArr: ",connArr) |
| | | } |
| | | } |