From a13ce6d465e7e06a9e187d617e1e76cfc8ffc40e Mon Sep 17 00:00:00 2001 From: JungJun Date: Thu, 23 Jun 2022 15:37:36 +0900 Subject: [PATCH] =?UTF-8?q?vg,=20va=20=EA=B5=AC=EB=B6=84=20=EB=B0=8F=20tcp?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icsapp/execsvc.go | 1 + icsstat/icsstat.go | 158 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 144 insertions(+), 15 deletions(-) diff --git a/icsapp/execsvc.go b/icsapp/execsvc.go index 06d6751..bb62089 100644 --- a/icsapp/execsvc.go +++ b/icsapp/execsvc.go @@ -34,6 +34,7 @@ func Init(conf *icsconf.IcsConfig) (e *IcsExec) { func (exe IcsExec) Execute() *icserror.IcsError { l := icslog.GetIcsLog() + icsstat.NewSidVal() for !exe.service.GetExit() { for exe.service.GetStop() { diff --git a/icsstat/icsstat.go b/icsstat/icsstat.go index 2699c04..9168592 100644 --- a/icsstat/icsstat.go +++ b/icsstat/icsstat.go @@ -3,6 +3,9 @@ package icsstat import ( "fmt" "io" + "math/rand" + "sync" + "time" "gitlab.com/ics_cinnamon/voiceStatistics/icsconf" "gitlab.com/ics_cinnamon/voiceStatistics/icserror" @@ -10,6 +13,11 @@ import ( "gitlab.com/ics_cinnamon/voiceStatistics/icsnet" ) +type SidVal struct { + Sid string + M *sync.Mutex +} + type StatInfos struct { //necessary value SeqId string // 25 @@ -45,6 +53,8 @@ type StatInfos struct { TtsText string // 1024 } +var gSidVal *SidVal + const ( //necessary value STAT_INFO = 0 @@ -92,7 +102,7 @@ func ListenStatMNG() (icserr *icserror.IcsError) { statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr) var cmdErr *icserror.IcsError - statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", StatsCommand) + statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", StatsCommandVG) if cmdErr != nil { l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError()) return nil @@ -114,7 +124,7 @@ func ListenStatMNG1() (icserr *icserror.IcsError) { statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr) var cmdErr *icserror.IcsError - statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", StatsCommand) + statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", StatsCommandVA) if cmdErr != nil { l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError()) return nil @@ -125,13 +135,38 @@ func ListenStatMNG1() (icserr *icserror.IcsError) { return nil } -func StatsCommand(t *icsnet.IcsTCPNet, bufend string) { +func NewSidVal() { + timeN := time.Now() + nano := fmt.Sprintf("%d", timeN.UTC().Nanosecond()) + sid := fmt.Sprintf("%02d%02d%02d%03s", timeN.Hour(), timeN.Minute(), timeN.Second(), nano[:3]) + gSidVal = &SidVal{ + Sid: sid, + } + gSidVal.M = &sync.Mutex{} +} + +func GetIcsSid() *SidVal { + return gSidVal +} + +func StatsCommandVG(t *icsnet.IcsTCPNet, bufend string) { l := icslog.GetIcsLog() statInfos := new(StatInfos) - count := 0 + s := GetIcsSid() + randNum := fmt.Sprintf("%d4", rand.Intn(9999)) + + defer func() { + if err := recover(); err != nil { + l.Printf(icslog.LOG_LEVEL_WARN, -1, "%s\n", + icserror.ICSERRNETNotConnectError.GetMessage()) + if t != nil { + t.Close() + } + return + } + }() - defer t.Close() l.Printf(icslog.LOG_LEVEL_INFO, -1, "Connected from - %s", t.RemoteAddr()) for { @@ -140,20 +175,17 @@ func StatsCommand(t *icsnet.IcsTCPNet, bufend string) { if rerr.GetError() != io.EOF { l.Printf(icslog.LOG_LEVEL_ERROR, -1, "[Stat Command] ReadS Error! - %s[%d:%d]", rerr.GetError(), rlen, len(statReads)) - // 여기서 listen인데 - t.Close() - return - // t.Close() + break } } else { - seqId := fmt.Sprintf("%05d", count) + svc := statInfos.SvcType[0:1] + seqId := s.Sid + svc + randNum + fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen) statInfos.ChangeByteToString(statReads) insLog := "" - // insLog += fmt.Sprintf("%s\n", statInfos.CallId) insLog += fmt.Sprintf("seqId:%s\n", seqId) - // insLog += fmt.Sprintf("%s\n", statInfos.SeqId) insLog += fmt.Sprintf("LogTime:%s, ", statInfos.LogTime) insLog += fmt.Sprintf("LogType:%s, ", statInfos.LogType) insLog += fmt.Sprintf("Sid:%s, ", statInfos.Sid) @@ -213,9 +245,105 @@ func StatsCommand(t *icsnet.IcsTCPNet, bufend string) { fmt.Printf("stats- %s \n", statInfos.ResultMsg) fmt.Printf("stats- %s \n", statInfos.SttText) fmt.Printf("stats- %s \n", statInfos.TtsText) - // l.Printf(icslog.LOG_LEVEL_INFO, -1, "Recved Stat Command(%s) %d", ttsHeader, rlen) - count++ - // t.Close() + } + } +} + +func StatsCommandVA(t *icsnet.IcsTCPNet, bufend string) { + l := icslog.GetIcsLog() + statInfos := new(StatInfos) + + s := GetIcsSid() + randNum := fmt.Sprintf("%d4", rand.Intn(9999)) + + defer func() { + if err := recover(); err != nil { + l.Printf(icslog.LOG_LEVEL_WARN, -1, "%s\n", + icserror.ICSERRNETNotConnectError.GetMessage()) + if t != nil { + t.Close() + } + return + } + }() + + l.Printf(icslog.LOG_LEVEL_INFO, -1, "Connected from - %s", t.RemoteAddr()) + + for { + statReads, rlen, rerr := t.ReadS(10137, bufend) // 여기서 전체 몇 byte씩 읽어서 로그를 찍을건지 알아야함 + if rerr != nil { + if rerr.GetError() != io.EOF { + l.Printf(icslog.LOG_LEVEL_ERROR, -1, "[Stat Command] ReadS Error! - %s[%d:%d]", + rerr.GetError(), rlen, len(statReads)) + break + } + } else { + svc := statInfos.SvcType[0:1] + seqId := s.Sid + svc + randNum + fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen) + statInfos.ChangeByteToString(statReads) + + insLog := "" + insLog += fmt.Sprintf("seqId:%s", seqId) + insLog += fmt.Sprintf("LogTime:%s, ", statInfos.LogTime) + insLog += fmt.Sprintf("LogType:%s, ", statInfos.LogType) + insLog += fmt.Sprintf("Sid:%s, ", statInfos.Sid) + insLog += fmt.Sprintf("ResultCode:%s, ", statInfos.ResultCode) + insLog += fmt.Sprintf("ReqTime:%s, ", statInfos.ReqTime) + insLog += fmt.Sprintf("RspTime:%s, ", statInfos.RspTime) + insLog += fmt.Sprintf("ClientIp:%s, ", statInfos.ClientIp) + insLog += fmt.Sprintf("DevInfo:%s, ", statInfos.DevInfo) + insLog += fmt.Sprintf("OsInfo:%s, ", statInfos.OsInfo) + insLog += fmt.Sprintf("NwInfo:%s, ", statInfos.NwInfo) + insLog += fmt.Sprintf("SvcName:%s, ", statInfos.SvcName) + insLog += fmt.Sprintf("DevModel:%s, ", statInfos.DevModel) + insLog += fmt.Sprintf("CarrierType:%s, ", statInfos.CarrierType) + insLog += fmt.Sprintf("HostName:%s, ", statInfos.HostName) + insLog += fmt.Sprintf("ScnName:%s, ", statInfos.ScnName) + insLog += fmt.Sprintf("CallId:%s, ", statInfos.CallId) + insLog += fmt.Sprintf("TrId:%s, ", statInfos.TrId) + insLog += fmt.Sprintf("ConcCall:%s, ", statInfos.ConcCall) + insLog += fmt.Sprintf("SvcType:%s, ", statInfos.SvcType) + insLog += fmt.Sprintf("SvcReqTime:%s, ", statInfos.SvcReqTime) + insLog += fmt.Sprintf("SvcRspTime:%s, ", statInfos.SvcRspTime) + insLog += fmt.Sprintf("TransferNo:%s, ", statInfos.TransferNo) + insLog += fmt.Sprintf("CallTime:%s, ", statInfos.CallTime) + insLog += fmt.Sprintf("CallType:%s, ", statInfos.CallType) + insLog += fmt.Sprintf("FunName:%s, ", statInfos.FunName) + insLog += fmt.Sprintf("ResultMsg:%s, ", statInfos.ResultMsg) + insLog += fmt.Sprintf("SttText:%s, ", statInfos.SttText) + insLog += fmt.Sprintf("TtsText:%s\n", statInfos.TtsText) + l.Printf(icslog.LOG_LEVEL_INFO, -1, "%s", insLog) + + fmt.Printf("stats- %s \n", statInfos.SeqId) + fmt.Printf("stats- %s \n", statInfos.LogTime) + fmt.Printf("stats- %s \n", statInfos.LogType) + fmt.Printf("stats- %s \n", statInfos.Sid) + fmt.Printf("stats- %s \n", statInfos.ResultCode) + fmt.Printf("stats- %s \n", statInfos.ReqTime) + fmt.Printf("stats- %s \n", statInfos.RspTime) + fmt.Printf("stats- %s \n", statInfos.ClientIp) + fmt.Printf("stats- %s \n", statInfos.DevInfo) + fmt.Printf("stats- %s \n", statInfos.OsInfo) + fmt.Printf("stats- %s \n", statInfos.NwInfo) + fmt.Printf("stats- %s \n", statInfos.SvcName) + fmt.Printf("stats- %s \n", statInfos.DevModel) + fmt.Printf("stats- %s \n", statInfos.CarrierType) + fmt.Printf("stats- %s \n", statInfos.HostName) + fmt.Printf("stats- %s \n", statInfos.ScnName) + fmt.Printf("stats- %s \n", statInfos.CallId) + fmt.Printf("stats- %s \n", statInfos.TrId) + fmt.Printf("stats- %s \n", statInfos.ConcCall) + fmt.Printf("stats- %s \n", statInfos.SvcType) + fmt.Printf("stats- %s \n", statInfos.SvcReqTime) + fmt.Printf("stats- %s \n", statInfos.SvcRspTime) + fmt.Printf("stats- %s \n", statInfos.TransferNo) + fmt.Printf("stats- %s \n", statInfos.CallTime) + fmt.Printf("stats- %s \n", statInfos.CallType) + fmt.Printf("stats- %s \n", statInfos.FunName) + fmt.Printf("stats- %s \n", statInfos.ResultMsg) + fmt.Printf("stats- %s \n", statInfos.SttText) + fmt.Printf("stats- %s \n", statInfos.TtsText) } } }