You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

460 lines
16 KiB
Go

2 years ago
package icsstat
import (
"fmt"
"io"
"math/rand"
"sync"
"time"
2 years ago
"gitlab.com/ics_cinnamon/voiceStatistics/icsconf"
"gitlab.com/ics_cinnamon/voiceStatistics/icserror"
"gitlab.com/ics_cinnamon/voiceStatistics/icslog"
"gitlab.com/ics_cinnamon/voiceStatistics/icsnet"
)
2 years ago
type SeqVal struct {
Seq string
M *sync.Mutex
}
2 years ago
type Host struct {
HostName string
M *sync.Mutex
}
2 years ago
type StatInfos struct {
//necessary value
SeqId string // 25
LogTime string // 14
LogType string // 3
Sid string // 50
ResultCode string // 8
ReqTime string // 17
RspTime string // 17
ClientIp string // 40
DevInfo string // 5
OsInfo string // 50
NwInfo string // 5
SvcName string // 32
DevModel string // 50
CarrierType string // 1
HostName string // 32
ScnName string // 32
//not necessary
CallId string // 60
TrId string // 100
ConcCall string // 5
SvcType string // 20
SvcReqTime string // 17
SvcRspTime string // 17
2 years ago
TransferNo string // 20
CallTime string // 5
CallType string // 10
FunName string // 30
2 years ago
ResultMsg string // 256
SttText string // 8192
TtsText string // 1024
}
2 years ago
var gSeqVal *SeqVal
2 years ago
var ghost *Host
2 years ago
const (
//necessary value
STAT_INFO = 0
SEQ_ID = STAT_INFO + 25
LOG_TIME = SEQ_ID + 14
LOG_TYPE = LOG_TIME + 3
SID = LOG_TYPE + 50
RESULT_CODE = SID + 8
REQ_TIME = RESULT_CODE + 17
RES_TIME = REQ_TIME + 17
CLIENT_IP = RES_TIME + 40
DEV_INFO = CLIENT_IP + 5
OS_INFO = DEV_INFO + 50
NW_INFO = OS_INFO + 5
SVC_NAME = NW_INFO + 32
DEV_MODEL = SVC_NAME + 50
CARRIER_TYPE = DEV_MODEL + 1
HOST_NAME = CARRIER_TYPE + 32
SCN_NAME = HOST_NAME + 32
//not necessary
CALL_ID = SCN_NAME + 60
TR_ID = CALL_ID + 100
CONC_CALL = TR_ID + 5
SVC_TYPE = CONC_CALL + 20
SVC_REQ_TIME = SVC_TYPE + 17
SVC_RSP_TIME = SVC_REQ_TIME + 17
2 years ago
TRANSFER_NO = SVC_RSP_TIME + 20
CALL_TIME = TRANSFER_NO + 5
CALL_TYPE = CALL_TIME + 10
FUN_NAME = CALL_TYPE + 30
RESULT_MSG = FUN_NAME + 255
STT_TEXT = RESULT_MSG + 8192
TTS_TEXT = STT_TEXT + 1024
2 years ago
)
func ListenStatMNG() (icserr *icserror.IcsError) {
2 years ago
// l := icslog.GetIcsLog()
2 years ago
conf := icsconf.GetIcsConfig()
//start bot-command listen
statPort := conf.Target.TargetPort
statTransport := conf.Target.Transport
statLocalAddrStr := fmt.Sprintf("0.0.0.0:%d", statPort)
statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr)
var cmdErr *icserror.IcsError
2 years ago
statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n", StatsCommandVG)
2 years ago
if cmdErr != nil {
2 years ago
// l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError())
2 years ago
return nil
}
2 years ago
fmt.Printf("Listening Stat TCP Command %s port[%d]", statTransport, statPort)
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listening Stat TCP Command %s port[%d]", statTransport, statPort)
2 years ago
fmt.Println(statTCP)
return nil
}
func ListenStatMNG1() (icserr *icserror.IcsError) {
2 years ago
// l := icslog.GetIcsLog()
conf := icsconf.GetIcsConfig()
//start bot-command listen
statPort := conf.Target1.TargetPort
statTransport := conf.Target1.Transport
statLocalAddrStr := fmt.Sprintf("0.0.0.0:%d", statPort)
statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr)
var cmdErr *icserror.IcsError
2 years ago
statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n", StatsCommandVA)
if cmdErr != nil {
2 years ago
// l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError())
return nil
}
2 years ago
fmt.Printf("Listening Stat TCP Command %s port[%d]", statTransport, statPort)
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listening Stat TCP Command %s port[%d]", statTransport, statPort)
fmt.Println(statTCP)
2 years ago
return nil
}
func NewSidVal() {
2 years ago
conf := icsconf.GetIcsConfig()
timeN := time.Now()
nano := fmt.Sprintf("%d", timeN.UTC().Nanosecond())
2 years ago
seq := fmt.Sprintf("%02d%02d%02d%03s", timeN.Hour(), timeN.Minute(), timeN.Second(), nano[:3])
gSeqVal = &SeqVal{
Seq: seq,
}
2 years ago
gSeqVal.M = &sync.Mutex{}
2 years ago
ghost = &Host{
HostName: conf.InfoConfig.HostName,
}
ghost.M = &sync.Mutex{}
}
2 years ago
func GetIcsSid() *SeqVal {
return gSeqVal
}
func StatsCommandVG(t *icsnet.IcsTCPNet, bufend string) {
2 years ago
l := icslog.GetIcsLog()
statInfos := new(StatInfos)
s := GetIcsSid()
randNum := fmt.Sprintf("%d4", rand.Intn(9999))
2 years ago
// 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()
2 years ago
2 years ago
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Connected from - %s", t.RemoteAddr())
2 years ago
2 years ago
// for {
statReads, rlen, rerr := t.ReadS(10137, bufend) // 여기서 전체 몇 byte씩 읽어서 로그를 찍을건지 알아야함
if rerr != nil {
if rerr.GetError() != io.EOF {
2 years ago
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "[Stat Command] ReadS Error! - %s[%d:%d]",
// rerr.GetError(), rlen, len(statReads))
2 years ago
return
}
2 years ago
} else {
fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen)
statInfos.ChangeByteToString(statReads)
svc := statInfos.SvcType[0:1]
seqId := s.Seq + svc + randNum
2 years ago
ghost.M.Lock()
hostName := ghost.HostName
ghost.M.Unlock()
2 years ago
insLog := ""
insLog += fmt.Sprintf("SEQ_ID=%s|", seqId)
insLog += fmt.Sprintf("LOG_TIME=%s|", statInfos.LogTime)
insLog += fmt.Sprintf("LOG_TYPE=%s|", statInfos.LogType)
insLog += fmt.Sprintf("SID=%s|", statInfos.Sid)
insLog += fmt.Sprintf("RESULT_CODE=%s|", statInfos.ResultCode)
insLog += fmt.Sprintf("REQ_TIME=%s|", statInfos.ReqTime)
insLog += fmt.Sprintf("RSP_TIME=%s|", statInfos.RspTime)
insLog += fmt.Sprintf("CLIENT_IP=%s|", statInfos.ClientIp)
insLog += fmt.Sprintf("DEV_INFO=%s|", statInfos.DevInfo)
insLog += fmt.Sprintf("OS_INFO=%s|", statInfos.OsInfo)
insLog += fmt.Sprintf("NW_INFO=%s|", statInfos.NwInfo)
insLog += fmt.Sprintf("SVC_NAME=%s|", statInfos.SvcName)
insLog += fmt.Sprintf("DEV_MODEL=%s|", statInfos.DevModel)
insLog += fmt.Sprintf("CARRIER_TYPE=%s|", statInfos.CarrierType)
insLog += fmt.Sprintf("HOST_NAME=%s|", hostName)
insLog += fmt.Sprintf("SCN_NAME=%s|", statInfos.ScnName)
insLog += fmt.Sprintf("CALL_ID=%s|", statInfos.CallId)
insLog += fmt.Sprintf("TR_ID=%s|", statInfos.TrId)
insLog += fmt.Sprintf("CONC_CALL=%s|", statInfos.ConcCall)
insLog += fmt.Sprintf("SVC_TYPE=%s|", statInfos.SvcType)
insLog += fmt.Sprintf("SVC_REQ_TIME=%s|", statInfos.SvcReqTime)
insLog += fmt.Sprintf("SVC_RSP_TIME=%s|", statInfos.SvcRspTime)
insLog += fmt.Sprintf("TRANSFER_NO=%s|", statInfos.TransferNo)
insLog += fmt.Sprintf("CALL_TIME=%s|", statInfos.CallTime)
insLog += fmt.Sprintf("CALL_TYPE=%s|", statInfos.CallType)
insLog += fmt.Sprintf("FUN_NAME=%s|", statInfos.FunName)
insLog += fmt.Sprintf("RESULT_MSG=%s|", statInfos.ResultMsg)
insLog += fmt.Sprintf("STT_TEXT=%s|", statInfos.SttText)
insLog += fmt.Sprintf("TTS_TEXT=%s", statInfos.TtsText)
2 years ago
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)
}
2 years ago
// }
}
func StatsCommandVA(t *icsnet.IcsTCPNet, bufend string) {
l := icslog.GetIcsLog()
statInfos := new(StatInfos)
s := GetIcsSid()
randNum := fmt.Sprintf("%d4", rand.Intn(9999))
2 years ago
defer t.Close()
2 years ago
statReads, rlen, rerr := t.ReadS(10137, bufend) // 여기서 전체 몇 byte씩 읽어서 로그를 찍을건지 알아야함
if rerr != nil {
if rerr.GetError() != io.EOF {
return
2 years ago
}
2 years ago
} else {
fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen)
statInfos.ChangeByteToString(statReads)
svc := statInfos.SvcType[0:1]
seqId := s.Seq + svc + randNum
2 years ago
ghost.M.Lock()
hostName := ghost.HostName
ghost.M.Unlock()
2 years ago
insLog := ""
insLog += fmt.Sprintf("SEQ_ID=%s|", seqId)
insLog += fmt.Sprintf("LOG_TIME=%s|", statInfos.LogTime)
insLog += fmt.Sprintf("LOG_TYPE=%s|", statInfos.LogType)
insLog += fmt.Sprintf("SID=%s|", statInfos.Sid)
insLog += fmt.Sprintf("RESULT_CODE=%s|", statInfos.ResultCode)
insLog += fmt.Sprintf("REQ_TIME=%s|", statInfos.ReqTime)
insLog += fmt.Sprintf("RSP_TIME=%s|", statInfos.RspTime)
insLog += fmt.Sprintf("CLIENT_IP=%s|", statInfos.ClientIp)
insLog += fmt.Sprintf("DEV_INFO=%s|", statInfos.DevInfo)
insLog += fmt.Sprintf("OS_INFO=%s|", statInfos.OsInfo)
insLog += fmt.Sprintf("NW_INFO=%s|", statInfos.NwInfo)
insLog += fmt.Sprintf("SVC_NAME=%s|", statInfos.SvcName)
insLog += fmt.Sprintf("DEV_MODEL=%s|", statInfos.DevModel)
insLog += fmt.Sprintf("CARRIER_TYPE=%s|", statInfos.CarrierType)
insLog += fmt.Sprintf("HOST_NAME=%s|", hostName)
insLog += fmt.Sprintf("SCN_NAME=%s|", statInfos.ScnName)
insLog += fmt.Sprintf("CALL_ID=%s|", statInfos.CallId)
insLog += fmt.Sprintf("TR_ID=%s|", statInfos.TrId)
insLog += fmt.Sprintf("CONC_CALL=%s|", statInfos.ConcCall)
insLog += fmt.Sprintf("SVC_TYPE=%s|", statInfos.SvcType)
insLog += fmt.Sprintf("SVC_REQ_TIME=%s|", statInfos.SvcReqTime)
insLog += fmt.Sprintf("SVC_RSP_TIME=%s|", statInfos.SvcRspTime)
insLog += fmt.Sprintf("TRANSFER_NO=%s|", statInfos.TransferNo)
insLog += fmt.Sprintf("CALL_TIME=%s|", statInfos.CallTime)
insLog += fmt.Sprintf("CALL_TYPE=%s|", statInfos.CallType)
insLog += fmt.Sprintf("FUN_NAME=%s|", statInfos.FunName)
insLog += fmt.Sprintf("RESULT_MSG=%s|", statInfos.ResultMsg)
insLog += fmt.Sprintf("STT_TEXT=%s|", statInfos.SttText)
insLog += fmt.Sprintf("TTS_TEXT=%s", 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)
2 years ago
}
}
2 years ago
func (statInfos *StatInfos) ChangeByteToString(statInfo []byte) *icserror.IcsError {
// l := icslog.GetIcsLog()
// defer func() {
// l.Printf(icslog.LOG_LEVEL_WARN, -1, "%s \n%s",
// icserror.ICSERRNETNotConnectError.GetMessage(), debug.Stack())
// return
// }()
2 years ago
// n := bytes.Index(statInfo[STAT_INFO:SEQ_ID], []byte{0})
statInfos.SeqId = string(statInfo[STAT_INFO:SEQ_ID])
// fmt.Println("seqid ", statInfo[STAT_INFO : SEQ_ID])
// n := bytes.Index(statInfo[SEQ_ID:LOG_TIME], []byte{0})
statInfos.LogTime = string(statInfo[SEQ_ID:LOG_TIME])
// fmt.Println("seqid ", statInfo[SEQ_ID : SEQ_ID+n])
// n = bytes.Index(statInfo[LOG_TIME:LOG_TYPE], []byte{0})
statInfos.LogType = string(statInfo[LOG_TIME:LOG_TYPE])
// fmt.Println("seqid ", statInfo[SEQ_ID : SEQ_ID+n])
// n = bytes.Index(statInfo[LOG_TYPE:SID], []byte{0})
statInfos.Sid = string(statInfo[LOG_TYPE:SID])
// n = bytes.Index(statInfo[SID:RESULT_CODE], []byte{0})
statInfos.ResultCode = string(statInfo[SID:RESULT_CODE])
// n = bytes.Index(statInfo[RESULT_CODE:REQ_TIME], []byte{0})
statInfos.ReqTime = string(statInfo[RESULT_CODE:REQ_TIME])
// n = bytes.Index(statInfo[REQ_TIME:RES_TIME], []byte{0})
statInfos.RspTime = string(statInfo[REQ_TIME:RES_TIME])
// n = bytes.Index(statInfo[RES_TIME:CLIENT_IP], []byte{0})
statInfos.ClientIp = string(statInfo[RES_TIME:CLIENT_IP])
// n = bytes.Index(statInfo[CLIENT_IP:DEV_INFO], []byte{0})
statInfos.DevInfo = string(statInfo[CLIENT_IP:DEV_INFO])
// n = bytes.Index(statInfo[DEV_INFO:OS_INFO], []byte{0})
statInfos.OsInfo = string(statInfo[DEV_INFO:OS_INFO])
// n = bytes.Index(statInfo[OS_INFO:NW_INFO], []byte{0})
statInfos.NwInfo = string(statInfo[OS_INFO:NW_INFO])
// n = bytes.Index(statInfo[NW_INFO:SVC_NAME], []byte{0})
statInfos.SvcName = string(statInfo[NW_INFO:SVC_NAME])
// n = bytes.Index(statInfo[SVC_NAME:DEV_MODEL], []byte{0})
statInfos.DevModel = string(statInfo[SVC_NAME:DEV_MODEL])
// n = bytes.Index(statInfo[DEV_MODEL:CARRIER_TYPE], []byte{0})
statInfos.CarrierType = string(statInfo[DEV_MODEL:CARRIER_TYPE])
// n = bytes.Index(statInfo[CARRIER_TYPE:HOST_NAME], []byte{0})
statInfos.HostName = string(statInfo[CARRIER_TYPE:HOST_NAME])
// n = bytes.Index(statInfo[HOST_NAME:SCN_NAME], []byte{0})
statInfos.ScnName = string(statInfo[HOST_NAME:SCN_NAME])
// n = bytes.Index(statInfo[SCN_NAME:CALL_ID], []byte{0})
statInfos.CallId = string(statInfo[SCN_NAME:CALL_ID])
// n = bytes.Index(statInfo[CALL_ID:TR_ID], []byte{0})
statInfos.TrId = string(statInfo[CALL_ID:TR_ID])
// n = bytes.Index(statInfo[TR_ID:CONC_CALL], []byte{0})
statInfos.ConcCall = string(statInfo[TR_ID:CONC_CALL])
// n = bytes.Index(statInfo[CONC_CALL:SVC_TYPE], []byte{0})
statInfos.SvcType = string(statInfo[CONC_CALL:SVC_TYPE])
// n = bytes.Index(statInfo[SVC_TYPE:SVC_REQ_TIME], []byte{0})
statInfos.SvcReqTime = string(statInfo[SVC_TYPE:SVC_REQ_TIME])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.SvcRspTime = string(statInfo[SVC_REQ_TIME:SVC_RSP_TIME])
2 years ago
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.TransferNo = string(statInfo[SVC_RSP_TIME:TRANSFER_NO])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.CallTime = string(statInfo[TRANSFER_NO:CALL_TIME])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.CallType = string(statInfo[CALL_TIME:CALL_TYPE])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.FunName = string(statInfo[CALL_TYPE:FUN_NAME])
2 years ago
// n = bytes.Index(statInfo[SVC_RSP_TIME:RESULT_MSG], []byte{0})
2 years ago
statInfos.ResultMsg = string(statInfo[FUN_NAME:RESULT_MSG])
2 years ago
// n = bytes.Index(statInfo[RESULT_MSG:STT_TEXT], []byte{0})
statInfos.SttText = string(statInfo[RESULT_MSG:STT_TEXT])
// n = bytes.Index(statInfo[STT_TEXT:TTS_TEXT], []byte{0})
statInfos.TtsText = string(statInfo[STT_TEXT:])
2 years ago
return nil
2 years ago
}