marge: 合并代码
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"ems.agt/restagent/config"
|
||||
"xorm.io/xorm"
|
||||
|
||||
wsService "ems.agt/src/modules/ws/service"
|
||||
"github.com/go-resty/resty/v2"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -47,17 +49,18 @@ type KpiReport struct {
|
||||
|
||||
type GoldKpi struct {
|
||||
// Id int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
Date string `json:"date" xorm:"date"`
|
||||
Index int `json:"index"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
NEName string `json:"neName" xorm:"ne_name"`
|
||||
RmUid string `json:"rmUid" xorm:"rm_uid"`
|
||||
NEType string `json:"neType" xorm:"ne_type"`
|
||||
KpiId string `json:"kpiId" xorm:"kpi_id"`
|
||||
Value int `json:"value"`
|
||||
Error string `json:"error"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Date string `json:"date" xorm:"date"`
|
||||
Index int `json:"index"`
|
||||
Granularity int8 `json:"granularity"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
NEName string `json:"neName" xorm:"ne_name"`
|
||||
RmUid string `json:"rmUid" xorm:"rm_uid"`
|
||||
NEType string `json:"neType" xorm:"ne_type"`
|
||||
KpiId string `json:"kpiId" xorm:"kpi_id"`
|
||||
Value int `json:"value"`
|
||||
Error string `json:"error"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -182,11 +185,26 @@ func PostKPIReportFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
goldKpi.Index, _ = strconv.Atoi(vars["index"])
|
||||
goldKpi.StartTime = global.GetFmtTimeString(layout, kpiReport.Task.Period.StartTime, time.DateTime)
|
||||
goldKpi.EndTime = global.GetFmtTimeString(layout, kpiReport.Task.Period.EndTime, time.DateTime)
|
||||
// get time granularity from startTime and endTime
|
||||
seconds, _ := global.GetSecondDuration(goldKpi.StartTime, goldKpi.EndTime)
|
||||
goldKpi.Granularity = 60
|
||||
if seconds != 0 && seconds <= math.MaxInt8 && seconds >= math.MinInt8 {
|
||||
goldKpi.Granularity = int8(seconds)
|
||||
}
|
||||
goldKpi.NEName = kpiReport.Task.NE.NEName
|
||||
goldKpi.RmUid = kpiReport.Task.NE.RmUID
|
||||
goldKpi.NEType = kpiReport.Task.NE.NeType
|
||||
goldKpi.Timestamp = global.GetFmtTimeString(layout, kpiReport.Timestamp, time.DateTime)
|
||||
// 黄金指标事件对象
|
||||
kpiEvent := map[string]any{
|
||||
// kip_id ...
|
||||
"neType": goldKpi.NEType,
|
||||
"neName": goldKpi.NEName,
|
||||
"startIndex": goldKpi.Index,
|
||||
"timeGroup": goldKpi.StartTime,
|
||||
}
|
||||
for _, k := range kpiReport.Task.NE.KPIs {
|
||||
kpiEvent[k.KPIID] = k.Value // kip_id
|
||||
goldKpi.KpiId = k.KPIID
|
||||
goldKpi.Value = k.Value
|
||||
goldKpi.Error = k.Err
|
||||
@@ -224,6 +242,9 @@ func PostKPIReportFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// 推送到ws订阅组
|
||||
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_KPI, kpiEvent)
|
||||
|
||||
services.ResponseStatusOK200Null(w)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user