marge: 合并代码
This commit is contained in:
Binary file not shown.
@@ -1,7 +1,6 @@
|
||||
package backupEtcFromNE
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -40,17 +39,17 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
|
||||
options := data.(cron.JobData)
|
||||
sysJob := options.SysJob
|
||||
var params BarParams
|
||||
// var params BarParams
|
||||
|
||||
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
log.Infof("Repeat %v Job ID %s", options.Repeat, sysJob.JobID)
|
||||
|
||||
var nes []dborm.NeInfo
|
||||
_, err = dborm.XormGetAllNeInfo(&nes)
|
||||
_, err := dborm.XormGetAllNeInfo(&nes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -83,7 +82,33 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
|
||||
var scpCmd string
|
||||
ipType := global.ParseIPAddr(neInfo.Ip)
|
||||
if neTypeLower != "omc" {
|
||||
omcNetypeLower := strings.ToLower(config.GetYamlConfig().OMC.NeType)
|
||||
etcListIMS := "{*.yaml,mmtel,vars.cfg}"
|
||||
if config.GetYamlConfig().NE.EtcListIMS != "" {
|
||||
etcListIMS = config.GetYamlConfig().NE.EtcListIMS
|
||||
}
|
||||
switch neTypeLower {
|
||||
case omcNetypeLower:
|
||||
if ipType == global.IsIPv4 {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@%s:%s/etc/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.OmcDir, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
} else {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@[%s]:%s/etc/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.OmcDir, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
}
|
||||
|
||||
case "ims":
|
||||
if ipType == global.IsIPv4 {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@%s:%s/%s/%s %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.EtcDir, neTypeLower,
|
||||
etcListIMS, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
} else {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@[%s]:%s/%s/%s %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.EtcDir, neTypeLower,
|
||||
etcListIMS, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
}
|
||||
|
||||
default:
|
||||
if ipType == global.IsIPv4 {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@%s:%s/%s/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.EtcDir,
|
||||
@@ -93,14 +118,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
neInfo.Ip, config.GetYamlConfig().NE.EtcDir,
|
||||
neTypeLower, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
}
|
||||
} else {
|
||||
if ipType == global.IsIPv4 {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@%s:%s/etc/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.OmcDir, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
} else {
|
||||
scpCmd = fmt.Sprintf("scp -r %s@[%s]:%s/etc/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.OmcDir, config.GetYamlConfig().OMC.Backup, neTypeLower)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
zipFile := fmt.Sprintf("%s-%s-etc-%s.zip", neTypeLower, strings.ToLower(neInfo.NeId), time.Now().Format(global.DateData))
|
||||
|
||||
@@ -25,8 +25,8 @@ type MonitorController struct {
|
||||
// GET /load
|
||||
func (s *MonitorController) Load(c *gin.Context) {
|
||||
var querys struct {
|
||||
// 数据类型all/cpu/memory/io/network
|
||||
Type string `form:"type" binding:"required,oneof=all cpu memory io network"`
|
||||
// 数据类型all/load/cpu/memory/io/network
|
||||
Type string `form:"type" binding:"required,oneof=all load cpu memory io network"`
|
||||
// 开始时间
|
||||
StartTime int64 `form:"startTime" binding:"required"`
|
||||
// 结束时间
|
||||
|
||||
@@ -12,9 +12,9 @@ type MonitorNetwork struct {
|
||||
Up float64 `json:"up"`
|
||||
// 下行
|
||||
Down float64 `json:"down"`
|
||||
// 网元ID
|
||||
// 网元ID 本机#号
|
||||
NeType string `json:"neType"`
|
||||
// 网元类型
|
||||
// 网元类型 本机#号
|
||||
NeID string `json:"neId"`
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *MonitorImpl) SelectMonitorBase(query map[string]any) []model.MonitorBas
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&bases).Error
|
||||
err := dbConn.Order("create_time asc").Find(&bases).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorBase %v", err)
|
||||
return bases
|
||||
@@ -65,7 +65,7 @@ func (r *MonitorImpl) SelectMonitorIO(query map[string]any) []model.MonitorIO {
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&ios).Error
|
||||
err := dbConn.Order("create_time asc").Find(&ios).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorIO %v", err)
|
||||
return ios
|
||||
@@ -89,12 +89,14 @@ func (r *MonitorImpl) SelectMonitorNetwork(query map[string]any) []model.Monitor
|
||||
dbConn := r.db()
|
||||
if query["name"] != "" {
|
||||
dbConn = dbConn.Where("name = ?", query["name"])
|
||||
} else {
|
||||
dbConn = dbConn.Where("name = ?", "all")
|
||||
}
|
||||
if query["neType"] != "" && query["neId"] != "" {
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&networks).Error
|
||||
err := dbConn.Order("create_time asc").Find(&networks).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorNetwork %v", err)
|
||||
return networks
|
||||
|
||||
@@ -37,23 +37,26 @@ type MonitorImpl struct {
|
||||
|
||||
// RunMonitor 执行资源监控
|
||||
func (s *MonitorImpl) RunMonitor() {
|
||||
var itemModel model.MonitorBase
|
||||
itemModel.CreateTime = time.Now().UnixMilli()
|
||||
var itemBase model.MonitorBase
|
||||
itemBase.CreateTime = time.Now().UnixMilli()
|
||||
itemBase.NeType = "#"
|
||||
itemBase.NeID = "#"
|
||||
totalPercent, _ := cpu.Percent(3*time.Second, false)
|
||||
if len(totalPercent) == 1 {
|
||||
itemModel.CPU = totalPercent[0]
|
||||
itemBase.CPU = totalPercent[0]
|
||||
}
|
||||
cpuCount, _ := cpu.Counts(false)
|
||||
|
||||
loadInfo, _ := load.Avg()
|
||||
itemModel.CPULoad1 = loadInfo.Load1
|
||||
itemModel.CPULoad5 = loadInfo.Load5
|
||||
itemModel.CPULoad15 = loadInfo.Load15
|
||||
itemModel.LoadUsage = loadInfo.Load1 / (float64(cpuCount*2) * 0.75) * 100
|
||||
itemBase.CPULoad1 = loadInfo.Load1
|
||||
itemBase.CPULoad5 = loadInfo.Load5
|
||||
itemBase.CPULoad15 = loadInfo.Load15
|
||||
itemBase.LoadUsage = loadInfo.Load1 / (float64(cpuCount*2) * 0.75) * 100
|
||||
|
||||
memoryInfo, _ := mem.VirtualMemory()
|
||||
itemModel.Memory = memoryInfo.UsedPercent
|
||||
if err := s.monitorRepository.CreateMonitorBase(itemModel); err != nil {
|
||||
itemBase.Memory = memoryInfo.UsedPercent
|
||||
|
||||
if err := s.monitorRepository.CreateMonitorBase(itemBase); err != nil {
|
||||
logger.Errorf("CreateMonitorBase err: %v", err)
|
||||
}
|
||||
|
||||
@@ -128,7 +131,10 @@ func (s *MonitorImpl) saveIODataToDB(ctx context.Context, interval float64) {
|
||||
if io2.Name == io1.Name {
|
||||
var itemIO model.MonitorIO
|
||||
itemIO.CreateTime = timeMilli
|
||||
itemIO.NeType = "#"
|
||||
itemIO.NeID = "#"
|
||||
itemIO.Name = io1.Name
|
||||
|
||||
if io2.ReadBytes != 0 && io1.ReadBytes != 0 && io2.ReadBytes > io1.ReadBytes {
|
||||
itemIO.Read = int64(float64(io2.ReadBytes-io1.ReadBytes) / interval / 60)
|
||||
}
|
||||
@@ -189,6 +195,8 @@ func (s *MonitorImpl) saveNetDataToDB(ctx context.Context, interval float64) {
|
||||
if net2.Name == net1.Name {
|
||||
var itemNet model.MonitorNetwork
|
||||
itemNet.CreateTime = timeMilli
|
||||
itemNet.NeType = "#"
|
||||
itemNet.NeID = "#"
|
||||
itemNet.Name = net1.Name
|
||||
|
||||
if net2.BytesSent != 0 && net1.BytesSent != 0 && net2.BytesSent > net1.BytesSent {
|
||||
@@ -225,7 +233,7 @@ func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]any {
|
||||
backDatas := map[string]any{}
|
||||
|
||||
// 基本信息
|
||||
if infoType == "all" || infoType == "cpu" || infoType == "memory" {
|
||||
if infoType == "all" || infoType == "load" || infoType == "cpu" || infoType == "memory" {
|
||||
rows := s.monitorRepository.SelectMonitorBase(map[string]any{
|
||||
"startTime": startTimeMilli,
|
||||
"endTime": endTimeMilli,
|
||||
|
||||
@@ -393,7 +393,7 @@ func (s *SysUserController) Export(c *gin.Context) {
|
||||
fileName := fmt.Sprintf("user_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||
// 第一行表头标题
|
||||
headerCells := map[string]string{
|
||||
"A1": "用户序号",
|
||||
"A1": "用户编号",
|
||||
"B1": "登录名称",
|
||||
"C1": "用户名称",
|
||||
"D1": "用户邮箱",
|
||||
|
||||
@@ -246,13 +246,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
|
||||
if regular.ValidMobile(newSysUser.PhoneNumber) {
|
||||
uniquePhone := r.CheckUniquePhone(newSysUser.PhoneNumber, "")
|
||||
if !uniquePhone {
|
||||
msg := fmt.Sprintf("序号:%s 手机号码 %s 已存在", row["A"], row["E"])
|
||||
msg := fmt.Sprintf("用户编号:%s 手机号码 %s 已存在", row["A"], row["E"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("序号:%s 手机号码 %s 格式错误", row["A"], row["E"])
|
||||
msg := fmt.Sprintf("用户编号:%s 手机号码 %s 格式错误", row["A"], row["E"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
continue
|
||||
@@ -264,13 +264,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
|
||||
if regular.ValidEmail(newSysUser.Email) {
|
||||
uniqueEmail := r.CheckUniqueEmail(newSysUser.Email, "")
|
||||
if !uniqueEmail {
|
||||
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 已存在", row["A"], row["D"])
|
||||
msg := fmt.Sprintf("用户编号:%s 用户邮箱 %s 已存在", row["A"], row["D"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 格式错误", row["A"], row["D"])
|
||||
msg := fmt.Sprintf("用户编号:%s 用户邮箱 %s 格式错误", row["A"], row["D"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
continue
|
||||
@@ -283,11 +283,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
|
||||
newSysUser.CreateBy = operName
|
||||
insertId := r.InsertUser(newSysUser)
|
||||
if insertId != "" {
|
||||
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入成功", row["A"], row["B"])
|
||||
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 导入成功", row["A"], row["B"])
|
||||
successNum++
|
||||
successMsgArr = append(successMsgArr, msg)
|
||||
} else {
|
||||
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入失败", row["A"], row["B"])
|
||||
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 导入失败", row["A"], row["B"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
}
|
||||
@@ -300,11 +300,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
|
||||
newSysUser.UpdateBy = operName
|
||||
rows := r.UpdateUser(newSysUser)
|
||||
if rows > 0 {
|
||||
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新成功", row["A"], row["B"])
|
||||
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 更新成功", row["A"], row["B"])
|
||||
successNum++
|
||||
successMsgArr = append(successMsgArr, msg)
|
||||
} else {
|
||||
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新失败", row["A"], row["B"])
|
||||
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 更新失败", row["A"], row["B"])
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user