1
0

marge: 合并代码,包名变更be.ems

This commit is contained in:
TsMask
2024-03-18 15:22:47 +08:00
parent df904f5328
commit 78bd110b03
393 changed files with 7870 additions and 5170 deletions

View File

@@ -4,19 +4,19 @@ import (
"embed"
"fmt"
"ems.agt/src/framework/config"
"ems.agt/src/framework/errorcatch"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/security"
"ems.agt/src/modules/chart"
"ems.agt/src/modules/common"
"ems.agt/src/modules/crontask"
"ems.agt/src/modules/monitor"
networkdata "ems.agt/src/modules/network_data"
networkelement "ems.agt/src/modules/network_element"
"ems.agt/src/modules/system"
"ems.agt/src/modules/trace"
"ems.agt/src/modules/ws"
"be.ems/src/framework/config"
"be.ems/src/framework/errorcatch"
"be.ems/src/framework/middleware"
"be.ems/src/framework/middleware/security"
"be.ems/src/modules/chart"
"be.ems/src/modules/common"
"be.ems/src/modules/crontask"
"be.ems/src/modules/monitor"
networkdata "be.ems/src/modules/network_data"
networkelement "be.ems/src/modules/network_element"
"be.ems/src/modules/system"
"be.ems/src/modules/trace"
"be.ems/src/modules/ws"
"github.com/gin-gonic/gin"
)

View File

@@ -1,11 +1,11 @@
package src
import (
"ems.agt/src/framework/config"
"ems.agt/src/framework/cron"
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/redis"
"be.ems/src/framework/config"
"be.ems/src/framework/cron"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/framework/redis"
)
// 配置中心初始加载

View File

@@ -8,7 +8,7 @@ import (
"os"
"time"
libConfig "ems.agt/src/lib_features/config"
libConfig "be.ems/src/lib_features/config"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

View File

@@ -1,12 +1,12 @@
# 项目信息
framework:
name: "CN EMS"
version: "2.2401.1"
version: "2.2403.1"
# 应用服务配置
server:
# 服务端口
port: 3030
port: 33030
# 是否开启代理
proxy: false
@@ -65,6 +65,9 @@ upload:
- ".mp4"
- ".avi"
- ".rmvb"
# 软件包
- ".deb"
- ".rpm"
# cors 跨域
cors:
@@ -97,6 +100,8 @@ cors:
- "Accept-Language"
- "Accept"
- "Range"
# 非标准请求头
- "accessToken"
- "Accesstoken"
- "Operationtype"
# 设置 Access-Control-Expose-Headers 的值

View File

@@ -1,6 +1,6 @@
# 应用服务配置
server:
port: 3030
port: 33030
proxy: true
# security 安全

View File

@@ -19,3 +19,6 @@ const JWT_KEY = "user_id"
// 令牌-JWT标识用户登录账号字段
const JWT_NAME = "user_name"
// NMS北向使用-数据响应字段和请求头授权
const ACCESS_TOKEN = "accessToken"

View File

@@ -23,6 +23,9 @@ const (
// 切片
CHUNK = "chunk"
// 软件包
SOFTWARE = "software"
)
// 子路径类型映射
@@ -34,4 +37,5 @@ var UploadSubpath = map[string]string{
COMMON: "通用上传",
DOWNLOAD: "下载",
CHUNK: "切片",
SOFTWARE: "软件包",
}

View File

@@ -4,7 +4,7 @@ import (
"testing"
"time"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
// 参考文章:

View File

@@ -4,9 +4,9 @@ import (
"encoding/json"
"time"
"ems.agt/src/framework/constants/common"
"ems.agt/src/modules/monitor/model"
"ems.agt/src/modules/monitor/repository"
"be.ems/src/framework/constants/common"
"be.ems/src/modules/monitor/model"
"be.ems/src/modules/monitor/repository"
)
// 实例任务执行日志收集

View File

@@ -7,8 +7,8 @@ import (
"regexp"
"time"
"ems.agt/src/framework/config"
"ems.agt/src/framework/logger"
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
"gorm.io/driver/mysql"
"gorm.io/gorm"

View File

@@ -3,9 +3,9 @@ package errorcatch
import (
"fmt"
"ems.agt/src/framework/config"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"regexp"
systemService "ems.agt/src/modules/system/service"
systemService "be.ems/src/modules/system/service"
)
// localeItem 国际化数据项

View File

@@ -84,13 +84,13 @@ func (l *Logger) checkFile() {
currTime := time.Now()
if l.logDay != currTime.Day() {
l.logDay = currTime.Day()
l.rotateFile(currTime.AddDate(0, 0, -1).Format("20060102"))
l.rotateFile(currTime.AddDate(0, 0, -1).Format("2006-01-02"))
// 移除超过保存最长天数的文件
l.removeOldFile(currTime.AddDate(0, 0, -l.maxDay))
} else if fileInfo.Size() >= l.maxSize {
l.rotateFile(currTime.Format("20060102_150405"))
l.rotateFile(currTime.Format("2006-01-02_150405"))
} else if time.Since(fileInfo.ModTime()).Hours() > 24 {
l.rotateFile(fileInfo.ModTime().Format("20060102"))
l.rotateFile(fileInfo.ModTime().Format("2006-01-02"))
}
time.AfterFunc(1*time.Minute, l.checkFile)
@@ -100,7 +100,7 @@ func (l *Logger) checkFile() {
func (l *Logger) rotateFile(timeFormat string) {
l.fileHandle.Close()
newFileName := fmt.Sprintf("%s-%s", l.fileName, timeFormat)
newFileName := fmt.Sprintf("%s.%s", l.fileName, timeFormat)
newFilePath := filepath.Join(l.filePath, newFileName)
oldfilePath := filepath.Join(l.filePath, l.fileName)
@@ -134,14 +134,18 @@ func (l *Logger) removeOldFile(oldFileDate time.Time) {
}
for _, file := range files {
idx := strings.LastIndex(file.Name(), ".log-")
// 跳过非指定日志文件名
if !strings.HasPrefix(file.Name(), l.fileName+".") {
continue
}
idx := strings.LastIndex(file.Name(), ".")
if idx == -1 {
continue
}
dateStr := file.Name()[idx+5 : idx+13]
dateStr := file.Name()[idx+1 : idx+11]
// 解析日期字符串
fileDate, err := time.Parse("20060102", dateStr)
fileDate, err := time.Parse("2006-01-02", dateStr)
if err != nil {
l.Errorf("logger RemoveOldFile Parse err: %v", err.Error())
continue

View File

@@ -3,16 +3,17 @@ package collectlogs
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"time"
"ems.agt/src/framework/constants/common"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/service"
"be.ems/src/framework/constants/common"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/system/model"
"be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
)
@@ -83,14 +84,6 @@ func OptionNew(title, businessType string) Options {
}
}
// 敏感属性字段进行掩码
var maskProperties []string = []string{
"password",
"oldPassword",
"newPassword",
"confirmPassword",
}
// OperateLog 访问操作日志记录
//
// 请在用户身份授权认证校验后使用以便获取登录用户信息
@@ -136,15 +129,8 @@ func OperateLog(options Options) gin.HandlerFunc {
// 是否需要保存request参数和值
if options.IsSaveRequestData {
params := ctx.RequestParamsMap(c)
for k, v := range params {
// 敏感属性字段进行掩码
for _, s := range maskProperties {
if s == k {
params[k] = parse.SafeContent(v.(string))
break
}
}
}
// 敏感属性字段进行掩码
processSensitiveFields(params)
jsonStr, _ := json.Marshal(params)
paramsStr := string(jsonStr)
if len(paramsStr) > 2000 {
@@ -182,3 +168,50 @@ func OperateLog(options Options) gin.HandlerFunc {
service.NewSysLogOperateImpl.InsertSysLogOperate(operLog)
}
}
// 敏感属性字段进行掩码
var maskProperties []string = []string{
"password",
"privateKey",
"privatePassword",
"passPhrase",
"oldPassword",
"newPassword",
"confirmPassword",
}
// processSensitiveFields 处理敏感属性字段
func processSensitiveFields(obj interface{}) {
val := reflect.ValueOf(obj)
switch val.Kind() {
case reflect.Map:
for _, key := range val.MapKeys() {
value := val.MapIndex(key)
keyStr := key.Interface().(string)
// 遍历是否敏感属性
hasMaskKey := false
for _, v := range maskProperties {
if v == keyStr {
hasMaskKey = true
break
}
}
if hasMaskKey {
valueStr := value.Interface().(string)
if len(valueStr) > 100 {
valueStr = valueStr[0:100]
}
val.SetMapIndex(key, reflect.ValueOf(parse.SafeContent(valueStr)))
} else {
processSensitiveFields(value.Interface())
}
}
case reflect.Slice, reflect.Array:
for i := 0; i < val.Len(); i++ {
processSensitiveFields(val.Index(i).Interface())
}
}
}

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -3,12 +3,12 @@ package middleware
import (
"strings"
AdminConstants "ems.agt/src/framework/constants/admin"
commonConstants "ems.agt/src/framework/constants/common"
"ems.agt/src/framework/i18n"
ctxUtils "ems.agt/src/framework/utils/ctx"
tokenUtils "ems.agt/src/framework/utils/token"
"ems.agt/src/framework/vo/result"
AdminConstants "be.ems/src/framework/constants/admin"
commonConstants "be.ems/src/framework/constants/common"
"be.ems/src/framework/i18n"
ctxUtils "be.ems/src/framework/utils/ctx"
tokenUtils "be.ems/src/framework/utils/token"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)
@@ -21,6 +21,7 @@ var URL_WHITE_LIST = []string{
"/omcNeConfig",
"/cdrEvent",
"/upload-ue",
"/oauth/token",
}
// PreAuthorize 用户身份授权认证校验

View File

@@ -5,12 +5,12 @@ import (
"strings"
"time"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/ip2region"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/i18n"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/ip2region"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)

View File

@@ -5,12 +5,12 @@ import (
"strconv"
"time"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/ip2region"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/logger"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/ip2region"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)

View File

@@ -3,7 +3,7 @@ package middleware
import (
"time"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
"github.com/gin-gonic/gin"
)

View File

@@ -1,8 +1,8 @@
package security
import (
"ems.agt/src/framework/config"
"ems.agt/src/framework/utils/generate"
"be.ems/src/framework/config"
"be.ems/src/framework/utils/generate"
"github.com/gin-gonic/gin"
)

View File

@@ -3,7 +3,7 @@ package security
import (
"fmt"
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -1,7 +1,7 @@
package security
import (
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -1,7 +1,7 @@
package security
import (
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -3,8 +3,8 @@ package security
import (
"net/url"
"ems.agt/src/framework/config"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/config"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)

View File

@@ -1,7 +1,7 @@
package security
import (
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -1,7 +1,7 @@
package security
import (
"ems.agt/src/framework/config"
"be.ems/src/framework/config"
"github.com/gin-gonic/gin"
)

View File

@@ -6,8 +6,8 @@ import (
"strings"
"time"
"ems.agt/src/framework/config"
"ems.agt/src/framework/logger"
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
"github.com/redis/go-redis/v9"
)

View File

@@ -37,34 +37,6 @@ func Exec(cmdStr string) (string, error) {
return stdout.String(), nil
}
func ExecWithTimeOut(cmdStr string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.Command("bash", "-c", cmdStr)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("errCmdTimeout %v", err)
}
if err != nil {
errMsg := ""
if len(stderr.String()) != 0 {
errMsg = fmt.Sprintf("stderr: %s", stderr.String())
}
if len(stdout.String()) != 0 {
if len(errMsg) != 0 {
errMsg = fmt.Sprintf("%s; stdout: %s", errMsg, stdout.String())
} else {
errMsg = fmt.Sprintf("stdout: %s", stdout.String())
}
}
return errMsg, err
}
return stdout.String(), nil
}
func ExecCronjobWithTimeOut(cmdStr string, workdir string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
@@ -92,6 +64,7 @@ func ExecCronjobWithTimeOut(cmdStr string, workdir string, timeout time.Duration
return errMsg, err
}
// Execf 本地执行命令 列如:("ssh %s@%s", "user", "localhost")
func Execf(cmdStr string, a ...interface{}) (string, error) {
cmd := exec.Command("bash", "-c", fmt.Sprintf(cmdStr, a...))
var stdout, stderr bytes.Buffer
@@ -115,6 +88,36 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
return stdout.String(), nil
}
// ExecWithTimeOut 本地执行命令超时退出 列如:("ssh user@localhost", 20*time.Second)
func ExecWithTimeOut(cmdStr string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.Command("bash", "-c", cmdStr)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("errCmdTimeout %v", err)
}
if err != nil {
errMsg := ""
if len(stderr.String()) != 0 {
errMsg = fmt.Sprintf("stderr: %s", stderr.String())
}
if len(stdout.String()) != 0 {
if len(errMsg) != 0 {
errMsg = fmt.Sprintf("%s; stdout: %s", errMsg, stdout.String())
} else {
errMsg = fmt.Sprintf("stdout: %s", stdout.String())
}
}
return errMsg, err
}
return stdout.String(), nil
}
// ExecWithCheck 执行命令程序带参数 例如:("ls", "-r", "-l", "-s")
func ExecWithCheck(name string, a ...string) (string, error) {
cmd := exec.Command(name, a...)
var stdout, stderr bytes.Buffer

View File

@@ -0,0 +1,88 @@
package crypto
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
)
// aesKey 字符串AES加解密密钥
const aesKey = "AGT66VfY4SMaiT97"
// StringEncryptByAES 字符串AES加密
func StringEncryptByAES(text string) (string, error) {
if len(text) == 0 {
return "", nil
}
pass := []byte(text)
xpass, err := aesEncryptWithSalt([]byte(aesKey), pass)
if err == nil {
pass64 := base64.StdEncoding.EncodeToString(xpass)
return pass64, err
}
return "", err
}
// StringDecryptByAES 字符串AES解密
func StringDecryptByAES(text string) (string, error) {
if len(text) == 0 {
return "", nil
}
bytesPass, err := base64.StdEncoding.DecodeString(text)
if err != nil {
return "", err
}
var tpass []byte
tpass, err = aesDecryptWithSalt([]byte(aesKey), bytesPass)
if err == nil {
result := string(tpass[:])
return result, err
}
return "", err
}
// aesEncryptWithSalt AES加密
func aesEncryptWithSalt(key, plaintext []byte) ([]byte, error) {
blockSize := aes.BlockSize
padding := blockSize - len(plaintext)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
plaintext = append(plaintext, padtext...)
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
ciphertext := make([]byte, blockSize+len(plaintext))
iv := ciphertext[0:blockSize]
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
return nil, err
}
cbc := cipher.NewCBCEncrypter(block, iv)
cbc.CryptBlocks(ciphertext[blockSize:], plaintext)
return ciphertext, nil
}
// aesDecryptWithSalt AES解密
func aesDecryptWithSalt(key, ciphertext []byte) ([]byte, error) {
blockSize := aes.BlockSize
var block cipher.Block
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
if len(ciphertext) < blockSize {
return nil, fmt.Errorf("iciphertext too short")
}
iv := ciphertext[:blockSize]
ciphertext = ciphertext[blockSize:]
cbc := cipher.NewCBCDecrypter(block, iv)
cbc.CryptBlocks(ciphertext, ciphertext)
length := len(ciphertext)
unpadding := int(ciphertext[len(ciphertext)-1])
ciphertext = ciphertext[:(length - unpadding)]
return ciphertext, nil
}

View File

@@ -4,13 +4,13 @@ import (
"fmt"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/common"
"ems.agt/src/framework/constants/roledatascope"
"ems.agt/src/framework/constants/token"
"ems.agt/src/framework/utils/ip2region"
"ems.agt/src/framework/utils/ua"
"ems.agt/src/framework/vo"
"be.ems/src/framework/config"
"be.ems/src/framework/constants/common"
"be.ems/src/framework/constants/roledatascope"
"be.ems/src/framework/constants/token"
"be.ems/src/framework/utils/ip2region"
"be.ems/src/framework/utils/ua"
"be.ems/src/framework/vo"
"golang.org/x/text/language"
"github.com/gin-gonic/gin"
@@ -65,6 +65,15 @@ func IPAddrLocation(c *gin.Context) (string, string) {
// Authorization 解析请求头
func Authorization(c *gin.Context) string {
// Query请求查询
if authQuery, ok := c.GetQuery(token.ACCESS_TOKEN); ok && authQuery != "" {
return authQuery
}
// Header请求头
if authHeader := c.GetHeader(token.ACCESS_TOKEN); authHeader != "" {
return authHeader
}
// Query请求查询
if authQuery, ok := c.GetQuery(token.RESPONSE_FIELD); ok && authQuery != "" {
return authQuery

View File

@@ -3,7 +3,7 @@ package date
import (
"time"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
const (

View File

@@ -72,21 +72,23 @@ func Post(url string, data url.Values, headers map[string]string) ([]byte, error
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New(resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return body, errors.New(resp.Status)
}
return body, nil
}
// PostJSON 发送 POST 请求,并将请求体序列化为 JSON 格式
func PostJSON(url string, data any, headers map[string]string) ([]byte, error) {
client := &http.Client{}
client := &http.Client{
Timeout: 3 * time.Second, // 超时时间
}
jsonData, err := json.Marshal(data)
if err != nil {
@@ -110,15 +112,15 @@ func PostJSON(url string, data any, headers map[string]string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New(resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return body, errors.New(resp.Status)
}
return body, nil
}
@@ -177,7 +179,9 @@ func PostUploadFile(url string, params map[string]string, file *os.File) ([]byte
// PutJSON 发送 PUT 请求,并将请求体序列化为 JSON 格式
func PutJSON(url string, data any, headers map[string]string) ([]byte, error) {
client := &http.Client{}
client := &http.Client{
Timeout: 3 * time.Second, // 超时时间
}
jsonData, err := json.Marshal(data)
if err != nil {
@@ -199,15 +203,15 @@ func PutJSON(url string, data any, headers map[string]string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New(resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return body, errors.New(resp.Status)
}
return body, nil
}
@@ -230,14 +234,14 @@ func Delete(url string, headers map[string]string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New(resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return body, errors.New(resp.Status)
}
return body, nil
}

View File

@@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
// 写入CSV文件需要转换数据
@@ -15,7 +15,7 @@ import (
// data = append(data, []string{"姓名", "年龄", "城市"})
// data = append(data, []string{"1", "2", "3"})
// err := file.WriterCSVFile(data, filePath)
func WriterCSVFile(data [][]string, filePath string) error {
func WriterFileCSV(data [][]string, filePath string) error {
// 获取文件所在的目录路径
dirPath := filepath.Dir(filePath)
@@ -44,7 +44,7 @@ func WriterCSVFile(data [][]string, filePath string) error {
}
// 读取CSV文件转换map数据
func ReadCSVFile(filePath string) []map[string]string {
func ReadFileCSV(filePath string) []map[string]string {
// 创建 map 存储 CSV 数据
arr := make([]map[string]string, 0)

View File

@@ -7,9 +7,9 @@ import (
"path/filepath"
"time"
"ems.agt/src/framework/constants/uploadsubpath"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/date"
"be.ems/src/framework/constants/uploadsubpath"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/date"
"github.com/xuri/excelize/v2"
)

View File

@@ -11,13 +11,13 @@ import (
"strings"
"time"
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/uploadsubpath"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/generate"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/utils/regular"
"be.ems/src/framework/config"
"be.ems/src/framework/constants/uploadsubpath"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/date"
"be.ems/src/framework/utils/generate"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/utils/regular"
)
/**最大文件名长度 */

View File

@@ -0,0 +1,108 @@
package file
import (
"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"
"be.ems/src/framework/logger"
)
// WriterFileJSON 写入JSON文件
func WriterFileJSON(data any, filePath string) error {
// 获取文件所在的目录路径
dirPath := filepath.Dir(filePath)
// 确保文件夹路径存在
err := os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
logger.Errorf("CreateFile MkdirAll %v", err)
}
// 创建或打开文件
file, err := os.Create(filePath)
if err != nil {
return err
}
defer file.Close()
// 创建 JSON 编码器
encoder := json.NewEncoder(file)
// 将数据编码并写入文件
err = encoder.Encode(data)
if err != nil {
return err
}
return nil
}
// WriterFileJSONLine 写入JSON文件用 一行一个JSON
func WriterFileJSONLine(data []any, filePath string) error {
// 获取文件所在的目录路径
dirPath := filepath.Dir(filePath)
// 确保文件夹路径存在
err := os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
logger.Errorf("CreateFile MkdirAll %v", err)
}
// 创建或打开文件
file, err := os.Create(filePath)
if err != nil {
return err
}
defer file.Close()
// 创建一个 Writer 对象,用于将数据写入文件
writer := bufio.NewWriter(file)
for _, row := range data {
jsonData, err := json.Marshal(row)
if err != nil {
return err
}
// 写入 JSON 字符串到文件,并换行
fmt.Fprintln(writer, string(jsonData))
}
// 将缓冲区中的数据刷新到文件中
err = writer.Flush()
if err != nil {
logger.Errorf("CreateFile Flush %v", err)
return err
}
return nil
}
// ReadFileJSONLine 读取行JSON文件 一行一个JSON
func ReadFileJSONLine(filePath string) []string {
// 创建 map 存储数据
arr := make([]string, 0)
// 打开文本文件
file, err := os.Open(filePath)
if err != nil {
logger.Errorf("OpenFile Open %v", err)
return arr
}
defer file.Close()
// 创建一个 Scanner 对象,用于逐行读取文件内容
scanner := bufio.NewScanner(file)
if scanner.Err() != nil {
logger.Errorf("OpenFile NewScanner %v", scanner.Err())
return arr
}
for scanner.Scan() {
line := scanner.Text()
arr = append(arr, line)
}
return arr
}

View File

@@ -7,16 +7,17 @@ import (
"path/filepath"
"strings"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
// 写入Txt文件用,号分割 需要转换数据
// WriterFileTXT 写入txt文件 sep 分割符号 需要转换数据
//
// 例如:
// data := [][]string{}
// data = append(data, []string{"姓名", "年龄", "城市"})
// data = append(data, []string{"1", "2", "3"})
// err := file.WriterCSVFile(data, filePath)
func WriterTxtFile(data [][]string, filePath string) error {
// err := file.WriterFileTXT(data, filePath)
func WriterFileTXT(data [][]string, sep string, filePath string) error {
// 获取文件所在的目录路径
dirPath := filepath.Dir(filePath)
@@ -36,7 +37,7 @@ func WriterTxtFile(data [][]string, filePath string) error {
// 创建一个 Writer 对象,用于将数据写入文件
writer := bufio.NewWriter(file)
for _, row := range data {
line := strings.Join(row, ",")
line := strings.Join(row, sep)
fmt.Fprintln(writer, line)
}
@@ -49,15 +50,15 @@ func WriterTxtFile(data [][]string, filePath string) error {
return nil
}
// 读取Txt文件用,号分割 转换数组数据
func ReadTxtFile(filePath string) [][]string {
// 创建 map 存储 CSV 数据
// ReadFileTXT 读取Txt文件sep 分割符号 转换数组数据
func ReadFileTXT(sep string, filePath string) [][]string {
// 创建 map 存储数据
arr := make([][]string, 0)
// 打开文本文件
file, err := os.Open(filePath)
if err != nil {
logger.Errorf("ReadTxtFile Open %v", err)
logger.Errorf("OpenFile Open %v", err)
return arr
}
defer file.Close()
@@ -65,13 +66,13 @@ func ReadTxtFile(filePath string) [][]string {
// 创建一个 Scanner 对象,用于逐行读取文件内容
scanner := bufio.NewScanner(file)
if scanner.Err() != nil {
logger.Errorf("ReadTxtFile NewScanner %v", scanner.Err())
logger.Errorf("OpenFile NewScanner %v", scanner.Err())
return arr
}
for scanner.Scan() {
line := scanner.Text()
fields := strings.Split(line, ",")
fields := strings.Split(line, sep)
arr = append(arr, fields)
}

View File

@@ -9,7 +9,7 @@ import (
"sort"
"strconv"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
// transferToNewFile 读取目标文件转移到新路径下

View File

@@ -0,0 +1,111 @@
package file
import (
"archive/zip"
"fmt"
"io"
"os"
"path/filepath"
)
// CompressZipByFile 将单文件添加到 ZIP 压缩文件
func CompressZipByFile(zipFilePath, filePath string) error {
// 创建一个新的 ZIP 文件
newZipFile, err := os.Create(zipFilePath)
if err != nil {
return fmt.Errorf("创建 ZIP 文件失败: %w", err)
}
defer newZipFile.Close()
// 创建 ZIP 写入器
zipWriter := zip.NewWriter(newZipFile)
defer zipWriter.Close()
fileToCompress, err := os.Open(filePath)
if err != nil {
return fmt.Errorf("打开文件失败: %w", err)
}
defer fileToCompress.Close()
// 获取文件信息
fileInfo, err := fileToCompress.Stat()
if err != nil {
return fmt.Errorf("获取文件信息失败: %w", err)
}
// 创建文件头
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
return fmt.Errorf("创建文件头失败: %w", err)
}
// 设置文件头中的名称
header.Name = fileInfo.Name()
// 创建文件在 ZIP 中的写入器
writer, err := zipWriter.CreateHeader(header)
if err != nil {
return fmt.Errorf("创建文件写入器失败: %w", err)
}
// 将文件内容复制到 ZIP 文件中
_, err = io.Copy(writer, fileToCompress)
if err != nil {
return fmt.Errorf("将文件内容复制到 ZIP 失败: %w", err)
}
return nil
}
// CompressZipByDir 将目录下文件添加到 ZIP 压缩文件
func CompressZipByDir(zipFilePath, dirPath string) error {
// 创建输出文件
zipWriter, err := os.Create(zipFilePath)
if err != nil {
return err
}
defer zipWriter.Close()
// 创建 zip.Writer
zipWriterObj := zip.NewWriter(zipWriter)
defer zipWriterObj.Close()
// 遍历目录下的所有文件和子目录
err = filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// 忽略目录
if info.IsDir() {
return nil
}
// 创建文件条目
relativePath, err := filepath.Rel(dirPath, path)
if err != nil {
return err
}
fileEntry, err := zipWriterObj.Create(relativePath)
if err != nil {
return err
}
// 打开文件
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
// 写入文件内容到 ZIP 文件
_, err = io.Copy(fileEntry, file)
if err != nil {
return err
}
return nil
})
return err
}

View File

@@ -4,7 +4,7 @@ import (
"math/rand"
"time"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
gonanoid "github.com/matoous/go-nanoid/v2"
)

View File

@@ -5,7 +5,7 @@ import (
"strings"
"time"
"ems.agt/src/framework/logger"
"be.ems/src/framework/logger"
)
// 网络地址(内网)

View File

@@ -0,0 +1,139 @@
package ping
import (
"encoding/json"
"fmt"
"runtime"
"time"
probing "github.com/prometheus-community/pro-bing"
)
// Ping 探针发包参数
type Ping struct {
DesAddr string `json:"desAddr"` // 目的 IP 地址(字符串类型,必填)
VRFName string `json:"vrfName"` // VRF 名称(字符串类型,可选)
DSCP int `json:"dscp"` // DSCP 优先级整数类型可选取值范围0-63默认值0
SrcAddr string `json:"srcAddr"` // 源 IP 地址(字符串类型,可选)
SendInterval int `json:"sendInterval"` // 发包间隔整数类型可选单位毫秒取值范围10-10000默认值1000
TTL int `json:"ttl"` // TTL整数类型可选取值范围1-255默认值255
SentPkts int `json:"sentPkts"` // 发包数整数类型可选取值范围1-65535默认值5
Size int `json:"size"` // 报文大小整数类型可选取值范围36-8192默认值36
TimeOut int `json:"timeOut"` // 报文超时时间整数类型可选单位取值范围1-60默认值2
}
// CopyFrom 将map复制到当前同key名的结构体
func (p *Ping) CopyFrom(from any) error {
b, err := json.Marshal(from)
if err != nil {
return err
}
if err = json.Unmarshal(b, p); err != nil {
return err
}
return nil
}
// setDefaultValue 设置默认值
func (p *Ping) setDefaultValue() {
if p.SendInterval < 10 || p.SendInterval > 10000 {
p.SendInterval = 1000
}
if p.TTL < 1 || p.TTL > 255 {
p.TTL = 255
}
if p.SentPkts < 1 || p.SentPkts > 65535 {
p.SentPkts = 5
}
if p.Size < 36 || p.Size > 8192 {
p.Size = 36
}
if p.DSCP < 0 || p.DSCP > 63 {
p.DSCP = 0
}
if p.TimeOut < 1 || p.TimeOut > 60 {
p.TimeOut = 2
}
}
// Statistics ping数据结果
func (p *Ping) Statistics() (*probing.Statistics, error) {
p.setDefaultValue()
pinger, err := probing.NewPinger(p.DesAddr)
if err != nil {
return nil, err
}
if p.SrcAddr != "" {
pinger.Source = p.SrcAddr
}
pinger.Interval = time.Duration(p.SendInterval) * time.Millisecond
pinger.TTL = p.TTL
pinger.Count = p.SentPkts
pinger.Size = p.Size
pinger.Timeout = time.Duration(p.TimeOut) * time.Second
// 设置特权模式(需要管理员权限)
if runtime.GOOS == "windows" {
pinger.SetPrivileged(true)
}
err = pinger.Run()
if err != nil {
fmt.Println(err)
return nil, err
}
return pinger.Statistics(), nil
}
// StatsInfo ping基本信息
func (p *Ping) StatsInfo() (map[string]any, error) {
stats, err := p.Statistics()
if err != nil {
return nil, err
}
return map[string]any{
"minTime": stats.MinRtt.Milliseconds(), // 最小时延(整数类型,可选,单位:毫秒)
"maxTime": stats.MaxRtt.Milliseconds(), // 最大时延(整数类型,可选,单位:毫秒)
"avgTime": stats.AvgRtt.Milliseconds(), // 平均时延(整数类型,可选,单位:毫秒)
"lossRate": int64(stats.PacketLoss), // 丢包率(整数类型,可选,单位:%
"jitter": stats.StdDevRtt.Milliseconds(), // 时延抖动(整数类型,可选,单位:毫秒)
}, nil
}
// StatsInfo ping探测发送的所有往返时间
func (p *Ping) StatsRtt() (map[string][]map[string]any, error) {
stats, err := p.Statistics()
if err != nil {
return nil, err
}
data := map[string][]map[string]any{
// hopList 节点列表
"hopList": {
{
// hopIndex 序号
"hopIndex": 1,
// probeList 探测信息列表
"probeList": []map[string]any{
{
"probeIndex": 1, // probeIndex 探测报文序号
"hopAddress": "-", // hopAddress 地址
"probeTime": 0, // probeTime 探测时长
},
},
},
},
}
rtts := []map[string]any{}
for i, tts := range stats.Rtts {
rtts = append(rtts, map[string]any{
"probeIndex": i + 1, // probeIndex 探测报文序号
"hopAddress": stats.IPAddr.String(), // hopAddress 地址
"probeTime": tts.Milliseconds(), // probeTime 探测时长
})
}
data["hopList"][0]["probeList"] = rtts
return data, nil
}

View File

@@ -5,8 +5,9 @@ import (
"reflect"
"strconv"
"strings"
"time"
"ems.agt/src/framework/utils/parse"
"be.ems/src/framework/utils/parse"
)
// PageNumSize 分页页码记录数
@@ -64,6 +65,18 @@ func SetFieldValue(obj any, fieldName string, value any) {
floatValue = 0
}
fieldValue.SetFloat(floatValue)
case reflect.Struct:
fmt.Printf("%s 时间解析 %s %v \n", fieldName, fieldValue.Type(), value)
if fieldValue.Type() == reflect.TypeOf(time.Time{}) && value != nil {
// 解析 value 并转换为 time.Time 类型
parsedTime, err := time.Parse("2006-01-02 15:04:05 +0800 CST", fmt.Sprintf("%v", value))
if err != nil {
fmt.Println("时间解析出错:", err)
} else {
// 设置字段的值
fieldValue.Set(reflect.ValueOf(parsedTime))
}
}
default:
// 设置字段的值
fieldValue.Set(reflect.ValueOf(value).Convert(fieldValue.Type()))

View File

@@ -4,10 +4,10 @@ import (
"fmt"
"strings"
"ems.agt/src/framework/cmd"
"ems.agt/src/framework/config"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/parse"
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/cmd"
"be.ems/src/framework/utils/parse"
)
// FileListRow 文件列表行数据

View File

@@ -6,8 +6,8 @@ import (
"os/exec"
"path/filepath"
"ems.agt/src/framework/config"
"ems.agt/src/framework/logger"
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
)
// 网元NE 文件复制到远程文件

View File

@@ -0,0 +1,245 @@
package ssh
import (
"bytes"
"fmt"
"io"
"os"
"os/user"
"strings"
"sync"
"time"
"be.ems/src/framework/logger"
gossh "golang.org/x/crypto/ssh"
)
// ConnSSH 连接SSH对象
type ConnSSH struct {
User string `json:"user"` // 主机用户名
Addr string `json:"addr"` // 主机地址
Port int64 `json:"port"` // SSH端口
AuthMode string `json:"authMode"` // 认证模式0密码 1主机私钥
Password string `json:"password"` // 认证密码
PrivateKey string `json:"privateKey"` // 认证私钥
PassPhrase string `json:"passPhrase"` // 认证私钥密码
DialTimeOut time.Duration `json:"dialTimeOut"` // 连接超时断开
Client *gossh.Client `json:"client"`
LastResult string `json:"lastResult"` // 记最后一次执行命令的结果
}
// NewClient 创建SSH客户端
func (c *ConnSSH) NewClient() (*ConnSSH, error) {
// IPV6地址协议
proto := "tcp"
if strings.Contains(c.Addr, ":") {
proto = "tcp6"
c.Addr = fmt.Sprintf("[%s]", c.Addr)
}
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
// ssh客户端配置
config := &gossh.ClientConfig{}
config.SetDefaults()
config.HostKeyCallback = gossh.InsecureIgnoreHostKey()
config.User = c.User
// 默认等待5s
if c.DialTimeOut == 0 {
c.DialTimeOut = 5 * time.Second
}
config.Timeout = c.DialTimeOut
// 认证模式-0密码 1私钥
if c.AuthMode == "1" {
var signer gossh.Signer
var err error
if len(c.PassPhrase) != 0 {
signer, err = gossh.ParsePrivateKeyWithPassphrase([]byte(c.PrivateKey), []byte(c.PassPhrase))
} else {
signer, err = gossh.ParsePrivateKey([]byte(c.PrivateKey))
}
if err != nil {
logger.Errorf("NewClient parse private key => %s", err.Error())
return nil, err
}
config.Auth = []gossh.AuthMethod{gossh.PublicKeys(signer)}
} else {
config.Auth = []gossh.AuthMethod{gossh.Password(c.Password)}
}
client, err := gossh.Dial(proto, addr, config)
if nil != err {
logger.Errorf("NewClient dial => %s", err.Error())
return c, err
}
c.Client = client
return c, nil
}
// Close 关闭当前SSH客户端
func (c *ConnSSH) Close() {
if c.Client != nil {
c.Client.Close()
}
}
// NewClientByLocalPrivate 创建SSH客户端-本地私钥(~/.ssh/id_rsa)直连
//
// ssh.ConnSSH{
// User: "user",
// Addr: "192.168.x.x",
// Port: body.Port,
// }
func (c *ConnSSH) NewClientByLocalPrivate() (*ConnSSH, error) {
c.Port = 22
c.AuthMode = "1"
usr, err := user.Current()
if err != nil {
logger.Errorf("NewClientByLocal get current user => %s", err.Error())
return nil, err
}
// 读取用户默认的私钥文件
keyPath := fmt.Sprintf("%s/.ssh/id_rsa", usr.HomeDir)
key, err := os.ReadFile(keyPath)
if err != nil {
logger.Errorf("NewClientByLocal [%s] read private key => %s", usr.Username, err.Error())
return nil, err
}
c.PrivateKey = string(key)
return c.NewClient()
}
// RunCMD 执行单次命令
func (c *ConnSSH) RunCMD(cmd string) (string, error) {
if c.Client == nil {
if _, err := c.NewClient(); err != nil {
return "", err
}
}
session, err := c.Client.NewSession()
if err != nil {
logger.Errorf("RunCMD failed to create session: => %s", err.Error())
return "", err
}
defer session.Close()
buf, err := session.CombinedOutput(cmd)
if err != nil {
logger.Errorf("RunCMD failed run command: => %s", err.Error())
}
c.LastResult = string(buf)
return c.LastResult, err
}
// NewClient 创建SSH客户端会话对象
func (c *ConnSSH) NewClientSession(cols, rows int) (*SSHClientSession, error) {
sshSession, err := c.Client.NewSession()
if err != nil {
return nil, err
}
stdin, err := sshSession.StdinPipe()
if err != nil {
return nil, err
}
comboWriter := new(singleWriter)
sshSession.Stdout = comboWriter
sshSession.Stderr = comboWriter
modes := gossh.TerminalModes{
gossh.ECHO: 1,
gossh.TTY_OP_ISPEED: 14400,
gossh.TTY_OP_OSPEED: 14400,
}
if err := sshSession.RequestPty("xterm", rows, cols, modes); err != nil {
return nil, err
}
if err := sshSession.Shell(); err != nil {
return nil, err
}
return &SSHClientSession{
Stdin: stdin,
Stdout: comboWriter,
Session: sshSession,
}, nil
}
// SSHClientSession SSH客户端会话对象
type SSHClientSession struct {
Stdin io.WriteCloser
Stdout *singleWriter
Session *gossh.Session
}
// Close 关闭会话
func (s *SSHClientSession) Close() {
if s.Stdin != nil {
s.Stdin.Close()
}
if s.Stdout != nil {
s.Stdout = nil
}
if s.Session != nil {
s.Session.Close()
}
}
// Write 写入命令 回车(\n)才会执行
func (s *SSHClientSession) Write(cmd string) (int, error) {
if s.Stdin == nil {
return 0, fmt.Errorf("ssh client session is nil to content write failed")
}
return s.Stdin.Write([]byte(cmd))
}
// Read 读取结果 等待一会才有结果
func (s *SSHClientSession) Read() []byte {
if s.Stdout == nil {
return []byte{}
}
// time.Sleep(300 * time.Millisecond)
bs := s.Stdout.Bytes()
if len(bs) > 0 {
s.Stdout.Reset()
return bs
}
return []byte{}
}
// CombinedOutput 发送命令带结果返回
func (s *SSHClientSession) CombinedOutput(cmd string) (string, error) {
n, err := s.Write(cmd)
if n == 0 || err != nil {
return "", err
}
return string(s.Read()), nil
}
// singleWriter SSH客户端会话消息
type singleWriter struct {
b bytes.Buffer
mu sync.Mutex
}
func (w *singleWriter) Write(p []byte) (int, error) {
w.mu.Lock()
defer w.mu.Unlock()
return w.b.Write(p)
}
func (w *singleWriter) Bytes() []byte {
w.mu.Lock()
defer w.mu.Unlock()
return w.b.Bytes()
}
func (w *singleWriter) Reset() {
w.mu.Lock()
defer w.mu.Unlock()
w.b.Reset()
}

View File

@@ -0,0 +1,218 @@
package telnet
import (
"bytes"
"fmt"
"net"
"strings"
"time"
)
// ConnTelnet 连接telnet对象
type ConnTelnet struct {
User string `json:"user"` // 主机用户名
Addr string `json:"addr"` // 主机地址
Port int64 `json:"port"` // telnet端口
Password string `json:"password"` // 认证密码
DialTimeOut time.Duration `json:"dialTimeOut"` // 连接超时断开
Client *net.Conn `json:"client"`
LastResult string `json:"lastResult"` // 记最后一次执行命令的结果
}
// NewClient 创建Telnet客户端
func (c *ConnTelnet) NewClient() (*ConnTelnet, error) {
// IPV6地址协议
proto := "tcp"
if strings.Contains(c.Addr, ":") {
proto = "tcp6"
c.Addr = fmt.Sprintf("[%s]", c.Addr)
}
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
// 默认等待5s
if c.DialTimeOut == 0 {
c.DialTimeOut = 5 * time.Second
}
// 连接到 Telnet 服务器
client, err := net.DialTimeout(proto, addr, c.DialTimeOut)
if err != nil {
return nil, err
}
// 进行登录
time.Sleep(100 * time.Millisecond)
client.Write([]byte(c.User + "\r\n"))
time.Sleep(100 * time.Millisecond)
client.Write([]byte(c.Password + "\r\n"))
// fmt.Fprintln(client, c.User)
// fmt.Fprintln(client, c.Password)
c.Client = &client
return c, nil
}
// Close 关闭当前Telnet客户端
func (c *ConnTelnet) Close() {
if c.Client != nil {
(*c.Client).Close()
}
}
// RunCMD 执行单次命令
func (c *ConnTelnet) RunCMD(cmd string) (string, error) {
if c.Client == nil {
return "", fmt.Errorf("telnet client not connected")
}
conn := *c.Client
var buf bytes.Buffer
tmp := make([]byte, 1024)
// 排空连接登录的信息
for {
// 设置读取超时时间为100毫秒
conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
n, err := conn.Read(tmp)
if err != nil {
// 判断是否是超时错误
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
break
}
break
}
if n == 0 {
break
}
buf.Write(tmp[:n])
}
buf.Reset()
// 写入命令
_, err := conn.Write([]byte(cmd))
if err != nil {
return "", err
}
// 读取本次响应命令消息
for {
// 设置读取超时时间为1000毫秒
conn.SetReadDeadline(time.Now().Add(1000 * time.Millisecond))
n, err := conn.Read(tmp)
if err != nil {
// 判断是否是超时错误
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
break
}
break
}
if n == 0 {
break
}
buf.Write(tmp[:n])
}
defer buf.Reset()
c.LastResult = buf.String()
return c.LastResult, nil
}
// NewClient 创建Telnet客户端会话对象
func (c *ConnTelnet) NewClientSession() (*TelnetClientSession, error) {
if c.Client == nil {
return nil, fmt.Errorf("telnet client not connected")
}
conn := *c.Client
var buf bytes.Buffer
tmp := make([]byte, 1024)
// 排空连接登录的信息
for {
// 设置读取超时时间为5毫秒
conn.SetReadDeadline(time.Now().Add(5 * time.Millisecond))
n, err := conn.Read(tmp)
if err != nil {
// 判断是否是超时错误
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
break
}
break
}
if n == 0 {
break
}
buf.Write(tmp[:n])
}
buf.Reset()
return &TelnetClientSession{
Client: conn,
}, nil
}
// TelnetClientSession Telnet客户端会话对象
type TelnetClientSession struct {
Client net.Conn
}
// Close 关闭会话
func (s *TelnetClientSession) Close() {
if s.Client != nil {
s.Client.Close()
}
}
// Write 写入命令 不带回车(\n)也会执行根据客户端情况
func (s *TelnetClientSession) Write(cmd string) (int, error) {
if s.Client == nil {
return 0, fmt.Errorf("client is nil to content write failed")
}
return s.Client.Write([]byte(cmd))
}
// Read 读取结果 等待一会才有结果
func (s *TelnetClientSession) Read() []byte {
if s.Client == nil {
return []byte{}
}
buf := make([]byte, 1024)
// 设置读取超时时间为100毫秒
s.Client.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
_, err := s.Client.Read(buf)
if err != nil {
return []byte{}
}
return buf
}
// CombinedOutput 发送命令带结果返回
func (s *TelnetClientSession) CombinedOutput(cmd string) (string, error) {
n, err := s.Write(cmd)
if n == 0 || err != nil {
return "", err
}
var buf bytes.Buffer
tmp := make([]byte, 1024)
for {
// 设置读取超时时间为1000毫秒
s.Client.SetReadDeadline(time.Now().Add(1000 * time.Millisecond))
n, err := s.Client.Read(tmp)
if err != nil {
// 判断是否是超时错误
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
break
}
break
}
if n == 0 {
break
}
buf.Write(tmp[:n])
}
defer buf.Reset()
return buf.String(), nil
}

View File

@@ -5,13 +5,13 @@ import (
"fmt"
"time"
"ems.agt/src/framework/config"
cachekeyConstants "ems.agt/src/framework/constants/cachekey"
tokenConstants "ems.agt/src/framework/constants/token"
"ems.agt/src/framework/logger"
redisCahe "ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/generate"
"ems.agt/src/framework/vo"
"be.ems/src/framework/config"
cachekeyConstants "be.ems/src/framework/constants/cachekey"
tokenConstants "be.ems/src/framework/constants/token"
"be.ems/src/framework/logger"
redisCahe "be.ems/src/framework/redis"
"be.ems/src/framework/utils/generate"
"be.ems/src/framework/vo"
jwt "github.com/golang-jwt/jwt/v5"
)

View File

@@ -1,6 +1,6 @@
package vo
import systemModel "ems.agt/src/modules/system/model"
import systemModel "be.ems/src/modules/system/model"
// LoginUser 登录用户身份权限信息对象
type LoginUser struct {

View File

@@ -1,7 +1,7 @@
package result
import (
"ems.agt/src/framework/constants/result"
"be.ems/src/framework/constants/result"
)
// CodeMsg 响应结果

View File

@@ -1,6 +1,6 @@
package vo
import systemModel "ems.agt/src/modules/system/model"
import systemModel "be.ems/src/modules/system/model"
// TreeSelect 树结构实体类
type TreeSelect struct {

View File

@@ -3,11 +3,11 @@ package libfeatures
import (
"time"
"ems.agt/lib/dborm"
"ems.agt/lib/oauth"
libConfig "ems.agt/restagent/config"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/redis"
"be.ems/lib/dborm"
"be.ems/lib/oauth"
libConfig "be.ems/restagent/config"
"be.ems/src/framework/logger"
"be.ems/src/framework/redis"
)
// SessionToken 设置登录会话-兼容旧登录方式

View File

@@ -3,9 +3,9 @@ package libfeatures
import (
"fmt"
libConf "ems.agt/lib/core/conf"
libGlobal "ems.agt/lib/global"
libConfig "ems.agt/restagent/config"
libConf "be.ems/lib/core/conf"
libGlobal "be.ems/lib/global"
libConfig "be.ems/restagent/config"
"github.com/spf13/viper"
)

View File

@@ -3,8 +3,8 @@ package session
import (
"time"
libConfig "ems.agt/restagent/config"
"ems.agt/src/framework/redis"
libConfig "be.ems/restagent/config"
"be.ems/src/framework/redis"
"github.com/gin-gonic/gin"
)

View File

@@ -1,10 +1,10 @@
package chart
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/collectlogs"
"ems.agt/src/modules/chart/controller"
"be.ems/src/framework/logger"
"be.ems/src/framework/middleware"
"be.ems/src/framework/middleware/collectlogs"
"be.ems/src/modules/chart/controller"
"github.com/gin-gonic/gin"
)

View File

@@ -1,10 +1,10 @@
package controller
import (
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo/result"
chartService "ems.agt/src/modules/chart/service"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
chartService "be.ems/src/modules/chart/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)

View File

@@ -1,6 +1,6 @@
package repository
import "ems.agt/src/modules/chart/model"
import "be.ems/src/modules/chart/model"
// G6关系图数据 数据层接口
type IChartGraph interface {

View File

@@ -3,11 +3,11 @@ package repository
import (
"strings"
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/utils/repo"
"ems.agt/src/modules/chart/model"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/utils/repo"
"be.ems/src/modules/chart/model"
)
// 实例化数据层 NewChartGraphImpl 结构体

View File

@@ -3,9 +3,9 @@ package service
import (
"strings"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/modules/chart/model"
chartRepository "ems.agt/src/modules/chart/repository"
"be.ems/src/framework/utils/parse"
"be.ems/src/modules/chart/model"
chartRepository "be.ems/src/modules/chart/repository"
"github.com/goccy/go-json"
)

View File

@@ -1,9 +1,9 @@
package common
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/modules/common/controller"
"be.ems/src/framework/logger"
"be.ems/src/framework/middleware"
"be.ems/src/modules/common/controller"
"github.com/gin-gonic/gin"
)

View File

@@ -1,18 +1,18 @@
package controller
import (
"ems.agt/src/framework/config"
commonConstants "ems.agt/src/framework/constants/common"
tokenConstants "ems.agt/src/framework/constants/token"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
tokenUtils "ems.agt/src/framework/utils/token"
"ems.agt/src/framework/vo"
"ems.agt/src/framework/vo/result"
libAccount "ems.agt/src/lib_features/account"
commonModel "ems.agt/src/modules/common/model"
commonService "ems.agt/src/modules/common/service"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/config"
commonConstants "be.ems/src/framework/constants/common"
tokenConstants "be.ems/src/framework/constants/token"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
tokenUtils "be.ems/src/framework/utils/token"
"be.ems/src/framework/vo"
"be.ems/src/framework/vo/result"
libAccount "be.ems/src/lib_features/account"
commonModel "be.ems/src/modules/common/model"
commonService "be.ems/src/modules/common/service"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
)

View File

@@ -3,14 +3,14 @@ package controller
import (
"time"
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/constants/captcha"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/vo/result"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/config"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/constants/captcha"
"be.ems/src/framework/logger"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"

View File

@@ -1,10 +1,10 @@
package controller
import (
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo/result"
commonService "ems.agt/src/modules/common/service"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
commonService "be.ems/src/modules/common/service"
"github.com/gin-gonic/gin"
)

View File

@@ -7,12 +7,12 @@ import (
"path/filepath"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/uploadsubpath"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/config"
"be.ems/src/framework/constants/uploadsubpath"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

View File

@@ -3,8 +3,8 @@ package controller
import (
"fmt"
"ems.agt/src/framework/config"
"ems.agt/src/framework/vo/result"
"be.ems/src/framework/config"
"be.ems/src/framework/vo/result"
"github.com/gin-gonic/gin"
)

View File

@@ -1,14 +1,14 @@
package controller
import (
commonConstants "ems.agt/src/framework/constants/common"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/regular"
"ems.agt/src/framework/vo/result"
commonModel "ems.agt/src/modules/common/model"
commonService "ems.agt/src/modules/common/service"
systemService "ems.agt/src/modules/system/service"
commonConstants "be.ems/src/framework/constants/common"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/regular"
"be.ems/src/framework/vo/result"
commonModel "be.ems/src/modules/common/model"
commonService "be.ems/src/modules/common/service"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
)

View File

@@ -1,6 +1,6 @@
package service
import "ems.agt/src/framework/vo"
import "be.ems/src/framework/vo"
// 账号身份操作服务 服务层接口
type IAccount interface {

View File

@@ -4,16 +4,16 @@ import (
"fmt"
"time"
"ems.agt/src/framework/config"
adminConstants "ems.agt/src/framework/constants/admin"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/constants/common"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/crypto"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/vo"
"ems.agt/src/modules/system/model"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/config"
adminConstants "be.ems/src/framework/constants/admin"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/constants/common"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/crypto"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo"
"be.ems/src/modules/system/model"
systemService "be.ems/src/modules/system/service"
)
// 实例化服务层 AccountImpl 结构体

View File

@@ -3,9 +3,9 @@ package service
import (
"fmt"
"ems.agt/lib/global"
"ems.agt/src/framework/config"
systemService "ems.agt/src/modules/system/service"
"be.ems/lib/global"
"be.ems/src/framework/config"
systemService "be.ems/src/modules/system/service"
)
// 实例化服务层 CommontImpl 结构体

View File

@@ -3,12 +3,12 @@ package service
import (
"fmt"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/constants/common"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/parse"
systemModel "ems.agt/src/modules/system/model"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/constants/common"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/parse"
systemModel "be.ems/src/modules/system/model"
systemService "be.ems/src/modules/system/service"
)
// 实例化服务层 RegisterImpl 结构体

View File

@@ -1,145 +0,0 @@
package backupEtcFromNE
import (
"encoding/json"
"fmt"
"os"
"strings"
"time"
"ems.agt/lib/dborm"
"ems.agt/lib/global"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
)
var NewProcessor = &BarProcessor{
progress: 0,
count: 0,
}
// bar 队列任务处理
type BarProcessor struct {
// 任务进度
progress int
// 执行次数
count int
}
type BarParams struct {
Duration int `json:"duration"`
TableName string `json:"tableName"`
ColName string `json:"colName"` // column name of time string
Extras string `json:"extras"` // extras condition for where
}
func (s *BarProcessor) Execute(data any) (any, error) {
log.Infof("execute %dlast progress %d ", s.count, s.progress)
s.count++
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
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)
if err != nil {
return nil, err
}
var successfulNEs, failureNEs []string
for _, neInfo := range nes {
neTypeUpper := strings.ToUpper(neInfo.NeType)
neTypeLower := strings.ToLower(neInfo.NeType)
nePath := fmt.Sprintf("%s/etc/%s", config.GetYamlConfig().OMC.Backup, neTypeLower)
isExist, err := global.PathExists(nePath)
if err != nil {
log.Errorf("Failed to PathExists:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
if isExist {
err = os.RemoveAll(nePath)
if err != nil {
log.Errorf("Failed to RemoveAll:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
}
err = os.MkdirAll(nePath, os.ModePerm)
if err != nil {
log.Errorf("Failed to MkdirAll:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
var scpCmd string
ipType := global.ParseIPAddr(neInfo.Ip)
if neTypeLower != "omc" {
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,
neTypeLower, config.GetYamlConfig().OMC.Backup, neTypeLower)
} else {
scpCmd = fmt.Sprintf("scp -r %s@[%s]:%s/%s/*.yaml %s/etc/%s", config.GetYamlConfig().NE.User,
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))
zipFilePath := config.GetYamlConfig().OMC.Backup + "/" + zipFile
zipCmd := fmt.Sprintf("cd %s/etc && zip -r %s %s/*", config.GetYamlConfig().OMC.Backup, zipFilePath, neTypeLower)
command := fmt.Sprintf("%s&&%s", scpCmd, zipCmd)
log.Trace("command:", command)
out, err := global.ExecCmd(command)
if err != nil {
log.Error("Faile to exec command:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
log.Tracef("command output:%s", out)
md5Sum, err := global.GetFileMD5Sum(zipFilePath)
if err != nil {
log.Error("Faile to md5sum:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
//log.Debug("md5Str:", md5Sum)
path := config.GetYamlConfig().OMC.Backup
neBackup := dborm.NeBackup{NeType: neTypeUpper, NeId: neInfo.NeId, FileName: zipFile, Path: path, Md5Sum: md5Sum}
_, err = dborm.XormInsertTableOne("ne_backup", neBackup)
if err != nil {
log.Error("Faile to XormInsertTableOne:", err)
failureNEs = append(failureNEs, neInfo.NeType+"/"+neInfo.NeId)
continue
}
successfulNEs = append(successfulNEs, neInfo.NeType+"/"+neInfo.NeId)
}
log.Infof("successfulNEs: %s failureNEs: %s", successfulNEs, failureNEs)
// result
return map[string]any{
"successfulNEs": successfulNEs,
"failureNEs": failureNEs,
}, nil
}

View File

@@ -1,8 +1,8 @@
package crontask
import (
"ems.agt/src/framework/logger"
"ems.agt/src/modules/crontask/processor"
"be.ems/src/framework/logger"
"be.ems/src/modules/crontask/processor"
"github.com/gin-gonic/gin"
)

View File

@@ -1,94 +0,0 @@
package delExpiredNeBackup
import (
"encoding/json"
"fmt"
"ems.agt/lib/dborm"
"ems.agt/lib/global"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
)
var NewProcessor = &BarProcessor{
progress: 0,
count: 0,
}
// bar 队列任务处理
type BarProcessor struct {
// 任务进度
progress int
// 执行次数
count int
}
type BarParams struct {
Duration int `json:"duration"`
}
func (s *BarProcessor) Execute(data any) (any, error) {
log.Infof("count: %d progress: %d ", s.count, s.progress)
s.count++
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
duration := 60
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
if err == nil {
duration = params.Duration
}
log.Infof("Repeat: %v JobID: %s", options.Repeat, sysJob.JobID)
// // 实现任务处理逻辑
// i := 0
// s.progress = i
// for i < 5 {
// // 获取任务进度
// progress := s.progress
// log.Infof("jonId: %s => 任务进度:%d", sysJob.JobID, progress)
// // 延迟响应
// time.Sleep(time.Second * 2)
// // 程序中途执行错误
// if i == 3 {
// // arr := [1]int{1}
// // arr[i] = 3
// // fmt.Println(arr)
// // return "i = 3"
// panic("程序中途执行错误")
// }
// i++
// // 改变任务进度
// s.progress = i
// }
where := fmt.Sprintf("NOW()>ADDDATE(`create_time`,interval %d day)", duration)
affected, err := dborm.XormDeleteDataByWhere(where, "ne_backup")
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
}
// delete expired files in backup directory
// todo ...
// command := fmt.Sprintf("find . -name '*.zip' -mtime +%d -type f -print | xargs rm -rf", duration)
command := fmt.Sprintf("%s/rmexpfiles.sh %s %d", config.GetYamlConfig().OMC.BinDir, config.GetYamlConfig().OMC.Backup, duration)
log.Trace("command:", command)
out, err := global.ExecCmd(command)
if err != nil {
log.Error("Faile to exec command:", err)
return nil, err
}
log.Tracef("command output:%s", out)
// 返回结果,用于记录执行结果
return map[string]any{
"msg": "success",
"cmdoutput": string(out),
"affected": affected,
}, nil
}

View File

@@ -1,88 +0,0 @@
package deleteExpiredRecord
import (
"encoding/json"
"fmt"
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/src/framework/cron"
)
var NewProcessor = &BarProcessor{
progress: 0,
count: 0,
}
// bar 队列任务处理
type BarProcessor struct {
// 任务进度
progress int
// 执行次数
count int
}
type BarParams struct {
Duration int `json:"duration"`
TableName string `json:"tableName"`
ColName string `json:"colName"` // column name of time string
Extras string `json:"extras"` // extras condition for where
}
func (s *BarProcessor) Execute(data any) (any, error) {
log.Infof("执行 %d 次,上次进度: %d ", s.count, s.progress)
s.count++
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
if err != nil {
return nil, err
}
//duration = params.Duration
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
// // 实现任务处理逻辑
// i := 0
// s.progress = i
// for i < 5 {
// // 获取任务进度
// progress := s.progress
// log.Infof("jonId: %s => 任务进度:%d", sysJob.JobID, progress)
// // 延迟响应
// time.Sleep(time.Second * 2)
// // 程序中途执行错误
// if i == 3 {
// // arr := [1]int{1}
// // arr[i] = 3
// // fmt.Println(arr)
// // return "i = 3"
// panic("程序中途执行错误")
// }
// i++
// // 改变任务进度
// s.progress = i
// }
var where string
if params.Extras == "" {
where = fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day)", params.ColName, params.Duration)
} else {
where = fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day) and %s", params.ColName, params.Duration, params.Extras)
}
affected, err := dborm.XormDeleteDataByWhere(where, params.TableName)
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
}
// 返回结果,用于记录执行结果
return map[string]any{
"msg": "sucess",
"affected": affected,
}, nil
}

View File

@@ -6,11 +6,11 @@ import (
"strings"
"time"
"ems.agt/lib/dborm"
"ems.agt/lib/global"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
"be.ems/lib/dborm"
"be.ems/lib/global"
"be.ems/lib/log"
"be.ems/restagent/config"
"be.ems/src/framework/cron"
)
var NewProcessor = &BarProcessor{

View File

@@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/src/framework/cron"
"be.ems/lib/dborm"
"be.ems/lib/log"
"be.ems/src/framework/cron"
)
var NewProcessor = &BarProcessor{

View File

@@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/src/framework/cron"
"be.ems/lib/dborm"
"be.ems/lib/log"
"be.ems/src/framework/cron"
)
var NewProcessor = &BarProcessor{

View File

@@ -8,12 +8,12 @@ import (
"strings"
"time"
"ems.agt/features/fm"
"ems.agt/lib/dborm"
"ems.agt/lib/global"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
"be.ems/features/fm"
"be.ems/lib/dborm"
"be.ems/lib/global"
"be.ems/lib/log"
"be.ems/restagent/config"
"be.ems/src/framework/cron"
"github.com/go-resty/resty/v2"
)

View File

@@ -7,10 +7,10 @@ import (
"strings"
"time"
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
"be.ems/lib/dborm"
"be.ems/lib/log"
"be.ems/restagent/config"
"be.ems/src/framework/cron"
"github.com/go-resty/resty/v2"
)

View File

@@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"ems.agt/src/framework/cron"
"ems.agt/src/framework/logger"
monitorService "ems.agt/src/modules/monitor/service"
"be.ems/src/framework/cron"
"be.ems/src/framework/logger"
monitorService "be.ems/src/modules/monitor/service"
)
var NewProcessor = &MonitorSysResourceProcessor{

View File

@@ -1,13 +1,13 @@
package processor
import (
"ems.agt/src/framework/cron"
"ems.agt/src/modules/crontask/processor/backupEtcFromNE"
"ems.agt/src/modules/crontask/processor/delExpiredNeBackup"
"ems.agt/src/modules/crontask/processor/deleteExpiredRecord"
"ems.agt/src/modules/crontask/processor/genNeStateAlarm"
"ems.agt/src/modules/crontask/processor/getStateFromNE"
monitorsysresource "ems.agt/src/modules/crontask/processor/monitor_sys_resource"
"be.ems/src/framework/cron"
"be.ems/src/modules/crontask/processor/backupEtcFromNE"
"be.ems/src/modules/crontask/processor/delExpiredNeBackup"
"be.ems/src/modules/crontask/processor/deleteExpiredRecord"
"be.ems/src/modules/crontask/processor/genNeStateAlarm"
"be.ems/src/modules/crontask/processor/getStateFromNE"
monitorsysresource "be.ems/src/modules/crontask/processor/monitor_sys_resource"
)
// InitCronQueue 初始定时任务队列

View File

@@ -1,10 +1,10 @@
package controller
import (
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/service"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/service"
"github.com/gin-gonic/gin"
)

View File

@@ -1,12 +1,12 @@
package controller
import (
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/model"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/i18n"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/model"
"github.com/gin-gonic/gin"
)

View File

@@ -7,14 +7,14 @@ import (
"strings"
"time"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/model"
"ems.agt/src/modules/monitor/service"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/model"
"be.ems/src/modules/monitor/service"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

View File

@@ -6,15 +6,15 @@ import (
"strings"
"time"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/model"
"ems.agt/src/modules/monitor/service"
systemService "ems.agt/src/modules/system/service"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/date"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/model"
"be.ems/src/modules/monitor/service"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
)

View File

@@ -5,14 +5,14 @@ import (
"sort"
"strings"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/redis"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/model"
"ems.agt/src/modules/monitor/service"
"be.ems/src/framework/constants/cachekey"
"be.ems/src/framework/i18n"
"be.ems/src/framework/redis"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/model"
"be.ems/src/modules/monitor/service"
"github.com/gin-gonic/gin"
)

View File

@@ -1,8 +1,8 @@
package controller
import (
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/monitor/service"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/monitor/service"
"github.com/gin-gonic/gin"
)

View File

@@ -1,13 +1,13 @@
package monitor
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/collectlogs"
"ems.agt/src/framework/middleware/repeat"
"ems.agt/src/modules/monitor/controller"
"ems.agt/src/modules/monitor/processor"
"ems.agt/src/modules/monitor/service"
"be.ems/src/framework/logger"
"be.ems/src/framework/middleware"
"be.ems/src/framework/middleware/collectlogs"
"be.ems/src/framework/middleware/repeat"
"be.ems/src/modules/monitor/controller"
"be.ems/src/modules/monitor/processor"
"be.ems/src/modules/monitor/service"
"github.com/gin-gonic/gin"
)

View File

@@ -3,8 +3,8 @@ package bar
import (
"time"
"ems.agt/src/framework/cron"
"ems.agt/src/framework/logger"
"be.ems/src/framework/cron"
"be.ems/src/framework/logger"
)
var NewProcessor = &BarProcessor{

View File

@@ -3,8 +3,8 @@ package foo
import (
"time"
"ems.agt/src/framework/cron"
"ems.agt/src/framework/logger"
"be.ems/src/framework/cron"
"be.ems/src/framework/logger"
)
var NewProcessor = &FooProcessor{

View File

@@ -1,10 +1,10 @@
package processor
import (
"ems.agt/src/framework/cron"
"ems.agt/src/modules/monitor/processor/bar"
"ems.agt/src/modules/monitor/processor/foo"
"ems.agt/src/modules/monitor/processor/simple"
"be.ems/src/framework/cron"
"be.ems/src/modules/monitor/processor/bar"
"be.ems/src/modules/monitor/processor/foo"
"be.ems/src/modules/monitor/processor/simple"
)
// InitCronQueue 初始定时任务队列

View File

@@ -1,8 +1,8 @@
package simple
import (
"ems.agt/src/framework/cron"
"ems.agt/src/framework/logger"
"be.ems/src/framework/cron"
"be.ems/src/framework/logger"
)
var NewProcessor = &simpleProcessor{}

View File

@@ -1,6 +1,6 @@
package repository
import "ems.agt/src/modules/monitor/model"
import "be.ems/src/modules/monitor/model"
// IMonitor 监控服务资源相关信息 数据接口
type IMonitor interface {

View File

@@ -1,9 +1,9 @@
package repository
import (
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/modules/monitor/model"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/modules/monitor/model"
"gorm.io/gorm"
)

View File

@@ -1,7 +1,7 @@
package repository
import (
"ems.agt/src/modules/monitor/model"
"be.ems/src/modules/monitor/model"
)
// ISysJob 调度任务表 数据层接口

View File

@@ -1,14 +1,15 @@
package repository
import (
"fmt"
"strings"
"time"
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/utils/repo"
"ems.agt/src/modules/monitor/model"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/utils/repo"
"be.ems/src/modules/monitor/model"
)
// 实例化数据层 SysJobImpl 结构体
@@ -209,11 +210,7 @@ func (r *SysJobImpl) CheckUniqueJob(sysJob model.SysJob) string {
return ""
}
if len(results) > 0 {
v, ok := results[0]["str"].(string)
if ok {
return v
}
return ""
return fmt.Sprint(results[0]["str"])
}
return ""
}

View File

@@ -1,7 +1,7 @@
package repository
import (
"ems.agt/src/modules/monitor/model"
"be.ems/src/modules/monitor/model"
)
// 调度任务日志表 数据层接口

View File

@@ -4,12 +4,12 @@ import (
"strings"
"time"
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/parse"
"ems.agt/src/framework/utils/repo"
"ems.agt/src/modules/monitor/model"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/date"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/utils/repo"
"be.ems/src/modules/monitor/model"
)
// 实例化数据层 SysJobLogImpl 结构体

Some files were not shown because too many files have changed in this diff Show More