1
0

merge: 合并代码

This commit is contained in:
TsMask
2024-04-30 20:37:27 +08:00
parent 78bd110b03
commit 3cc193f57d
95 changed files with 3028 additions and 1519 deletions

View File

@@ -11,16 +11,6 @@ import (
"gopkg.in/yaml.v3"
)
type DbConfig struct {
Type string `yaml:"type"`
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Name string `yaml:"name"`
Backup string `yaml:"backup"`
}
// Yaml struct of config
type YamlConfig struct {
Logger struct {
@@ -30,16 +20,18 @@ type YamlConfig struct {
Count int `yaml:"count"`
} `yaml:"logger"`
Rest []struct {
IPv4 string `yaml:"ipv4"`
IPv6 string `yaml:"ipv6"`
Port uint16 `yaml:"port"`
Scheme string `yaml:"scheme"`
ClientAuthType int `yaml:"clientAuthType"`
CaFile string `yaml:"caFile"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
} `yaml:"rest"`
// Rest []struct {
// IPv4 string `yaml:"ipv4"`
// IPv6 string `yaml:"ipv6"`
// Port uint16 `yaml:"port"`
// Scheme string `yaml:"scheme"`
// ClientAuthType int `yaml:"clientAuthType"`
// CaFile string `yaml:"caFile"`
// CertFile string `yaml:"certFile"`
// KeyFile string `yaml:"keyFile"`
// } `yaml:"rest"`
Rest []RestParam
WebServer struct {
Enabled bool `yaml:"enabled"`
@@ -85,7 +77,8 @@ type YamlConfig struct {
} `yaml:"omc"`
Alarm struct {
ForwardAlarm bool `yaml:"forwardAlarm"`
ForwardAlarm bool `yaml:"forwardAlarm"`
SMProxy string `yaml:"smProxy"`
Email struct {
Smtp string `yaml:"smtp"`
Port uint16 `yaml:"port"`
@@ -101,22 +94,14 @@ type YamlConfig struct {
TemplateCode string `yaml:"templateCode"`
} `yaml:"sms"`
SMSC struct {
Addr string `yaml:"addr"`
UserName string `yaml:"userName"`
Password string `yaml:"password"`
Addr string `yaml:"addr"`
SystemID string `yaml:"systemID"`
Password string `yaml:"password"`
SystemType string `yaml:"systemType"`
} `yaml:"smsc"`
} `yaml:"alarm"`
MML struct {
Port int `yaml:"port"`
Port2 int `yaml:"port2"`
Sleep int64 `yaml:"sleep"`
DeadLine int64 `yaml:"deadLine"`
User string `yaml:"user"`
Password string `ymal:"password"`
MmlHome string `yaml:"mmlHome"`
Upload string `yaml:"upload"`
} `yaml:"mml"`
MML MMLParam `yaml:"mml"`
NE struct {
Addr string `yaml:"addr"`
@@ -157,6 +142,42 @@ type YamlConfig struct {
} `yaml:"testConfig"`
}
type RestParam struct {
IPv4 string `yaml:"ipv4"`
IPv6 string `yaml:"ipv6"`
Port uint16 `yaml:"port"`
Scheme string `yaml:"scheme,omitempty" default:"http"`
ClientAuthType int `yaml:"clientAuthType"`
CaFile string `yaml:"caFile"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
}
type DbConfig struct {
Type string `yaml:"type"`
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Name string `yaml:"name"`
ConnParam string `yaml:"connParam,omitempty"`
Backup string `yaml:"backup"`
}
type MMLParam struct {
Port int `yaml:"port"`
Port2 int `yaml:"port2"`
Sleep int64 `yaml:"sleep"`
DeadLine int64 `yaml:"deadLine"`
SizeRow byte `yaml:"sizeRow"`
SizeCol byte `yaml:"sizeCol"`
BufferSize int `yaml:"bufferSize"`
User string `yaml:"user"`
Password string `ymal:"password"`
MmlHome string `yaml:"mmlHome"`
Upload string `yaml:"upload"`
}
type TestDatas struct {
UDM struct {
CapUsed uint32 `yaml:"capUsed"`
@@ -188,7 +209,22 @@ type TestDataMap struct {
NeTestDatas []map[string]NeTestData
}
var yamlConfig YamlConfig
var yamlConfig YamlConfig = NewYamlConfig()
// set default value for yaml config
func NewYamlConfig() YamlConfig {
return YamlConfig{
Database: DbConfig{
Type: "mysql",
ConnParam: "charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True",
},
MML: MMLParam{
SizeRow: 100,
SizeCol: 128,
BufferSize: 65535,
},
}
}
func ReadConfig(configFile string) {
yamlFile, err := os.ReadFile(configFile)
@@ -327,6 +363,23 @@ func GetDefaultUserAgent() string {
return "OMC-restagent/" + global.Version
}
func GetOMCHostUrl() string {
var omcip string = "127.0.0.1"
var rest RestParam = yamlConfig.Rest[0]
var port uint16 = rest.Port
if rest.IPv4 != "0.0.0.0" && rest.IPv4 != "" {
omcip = rest.IPv4
} else if rest.IPv6 != "::" && rest.IPv6 != "" {
omcip = "[" + rest.IPv6 + "]"
}
var scheme string = "http"
if rest.Scheme != "" {
scheme = rest.Scheme
}
return fmt.Sprintf("%s://%s:%d", scheme, omcip, port)
}
// const defaultConfigFile = "./etc/restconf.yaml"
// func init() {

View File

@@ -1,181 +0,0 @@
# file: log file name
# level: /trace/debug/info/warn/error/fatal, default: debug
# duration: rotation time with xx hours, example: 1/12/24 hours
# count: rotation count of log, default is 30 rotation
logger:
file: "../temp/log/restagent.log"
level: "trace"
duration: 24
count: 2
# rest agent listen ipv4/v6 and port, support multiple routines
# ip: 0.0.0.0 or ::0, support IPv4/v6
# clientAuthType: 0:NoClientCert (default), 1:RequestClientCert, 2:RequireAnyClientCert,
# 3:VerifyClientCertIfGiven, 4:RequireAndVerifyClientCerts
rest:
- ipv4: 0.0.0.0
ipv6:
port: 33040
- ipv4: 0.0.0.0
ipv6:
port: 33443
scheme: https
clientAuthType: 0
caFile: ./etc/certs/omc-ca.crt
certFile: ./etc/certs/omc-server.crt
keyFile: ./etc/certs/omc-server.key
webServer:
enabled: false
rootDir: d:/local.git/fe.ems.vue3/dist
listen:
- addr: :80
schema: http
- addr: :443
scheme: https
clientAuthType: 0
caFile: ./etc/certs/omc-ca.crt
certFile: ./etc/certs/omc-server.crt
keyFile: ./etc/certs/omc-server.key
database:
type: mysql
user: root
# password: 1000omc@kp!
# host: "192.168.8.103"
# port: 33066
name: omc_db
backup: d:/local.git/be.ems/restagent/database
password: "root@1234"
host: "192.168.5.59"
port: 3306
# Redis 缓存数据,数据源声明全小写
redis:
dataSource:
# OMC系统使用库
default:
port: 6379 # Redis port
host: "192.168.5.59" # Redis host
password: "redis@1234"
db: 10 # Redis db_num
# UDM网元用户库
udmuser:
port: 6379 # Redis port
host: "192.168.13.140"
password: ""
db: 0 # Redis db_num
# 多个数据源时可以用这个指定默认的数据源
defaultDataSourceName: "default"
# sleep: time delay for after write buffer (millisecond)
# deadLine: timeout for io read and write (second)
mml:
port: 4100
port2: 5002
sleep: 200
deadLine: 10
user: admin
password: admin
mmlHome: ./mmlhome
upload: /home/agtuser
# NE config
ne:
user: agtuser
etcdir: /usr/local/etc
bindir: /usr/local/bin
omcdir: /usr/local/omc
scpdir: /tmp
licensedir: /usr/local/etc/{neType}/license
# backup etc list of IMS,no space
etcListIMS: "{*.yaml,mmtel,vars.cfg}"
etcListDefault: "{*.yaml,*.conf,*.cfg}"
# true/false to overwrite config file when dpkg ne software
dpkgOverwrite: false
# dpkg timeout (second)
dpkgTimeout: 180
# chk2ne: true/false, if put OmcNeConfig parameters to NE
omc:
uriPrefix: "/omc/rest"
neType: OMC
neId: 001
rmUID: 4400HX101
neName: OMC
province: GD
vendor: ""
dn: 4600
chk2ne: false
sn: "-"
checksign: false
rootDir: ./
binDir: ./bin
backup: ./backup
upload: ./upload
frontUpload: d:/local.git/fe.ems/upload
frontTraceDir: d:/local.git/fe.ems/trace
software: ./software
license: ./license
gtpUri: gtp:192.168.2.219:2152
checkContentType: false
testMode: false
rbacMode: true
runDir:
cmdTimeout: 120
# Alarm module setting
# Forward interface:
# email/sms
alarm:
forwardAlarm: true
email:
smtp: mail.agrandtech.com
port: 25
user: smtpext@agrandtech.com
password: "1000smtp@omc!"
# TLS skip verify: true/false
tlsSkipVerify: true
sms:
apiURL: http://smsc.xxx.com.cn/
accessKeyID: xxxx
accessKeySecret: xxxx
signName: xxx SMSC
templateCode: 1000
smsc:
addr: "192.168.14.211:2775"
userName: OMC
password: "123456"
#User authorized information
# crypt: mysql/md5/bcrypt
# token: true/false to check accessToken
# expires for session, unit: second
# Support single/multiple session of user
#
auth:
crypt: bcrypt
token: true
expires: 1800
session: multiple
publicKey: ./etc/certs/omc_pub.key
privateKey: ./etc/certs/omc_pri.key
# Parameter for limit number
# rmuid_maxnum: the max number of rmUID, default: 50
# alarmid_maxnum: the max number of AlarmID, default: 50
# pmid_maxnum: the max number of pmID, default: 50
# subid_maxnum: the max number of subscription ID, default: 20
# uri_maxlen: the max length of uri, default: 8192
# rmuid_regexp: regexp pattern of rmUID
params:
rmuidmaxnum: 50
alarmidmaxnum: 50
pmidmaxnum: 50
subidmaxnum: 20
urimaxlen: 2100000
rmuidregexp: "[0-9]{4}[A-Z]{2}[A-Z]{2}[0-9A-Z]{1}[0-9A-Z]{3}[0-9A-Z]{1,16}"
testConfig:
enabled: true
file: ./etc/testconfig.yaml

View File

@@ -16,14 +16,6 @@ rest:
- ipv4: 0.0.0.0
ipv6:
port: 33040
- ipv4: 0.0.0.0
ipv6:
port: 33443
scheme: https
clientAuthType: 0
caFile: ./etc/certs/omc-ca.crt
certFile: ./etc/certs/omc-server.crt
keyFile: ./etc/certs/omc-server.key
webServer:
enabled: false
@@ -41,14 +33,12 @@ webServer:
database:
type: mysql
user: root
# password: 1000omc@kp!
# host: "192.168.8.103"
# port: 33066
name: omc_db
backup: d:/local.git/be.ems/restagent/database
password: "root@1234"
host: "192.168.5.59"
port: 3306
name: "omc_db"
connParam: charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True
backup: d:/local.git/be.ems/restagent/database
# Redis 缓存数据,数据源声明全小写
redis:
@@ -62,8 +52,8 @@ redis:
# UDM网元用户库
udmuser:
port: 6379 # Redis port
host: "192.168.13.140"
password: ""
host: "172.60.5.140"
password: "helloearth"
db: 0 # Redis db_num
# 多个数据源时可以用这个指定默认的数据源
defaultDataSourceName: "default"
@@ -75,6 +65,9 @@ mml:
port2: 5002
sleep: 200
deadLine: 10
sizeRow: 100
sizeCol: 128
bufferSize: 65535
user: admin
password: admin
mmlHome: ./mmlhome
@@ -128,7 +121,7 @@ omc:
# Forward interface:
# email/sms
alarm:
forwardAlarm: true
forwardAlarm: false
email:
smtp: mail.agrandtech.com
port: 25
@@ -143,9 +136,10 @@ alarm:
signName: xxx SMSC
templateCode: 1000
smsc:
addr: "192.168.14.211:2775"
userName: OMC
password: "123456"
addr: "192.168.13.114:2775"
systemID: "omc"
password: "omc123"
systemType: "UTRAN"
#User authorized information
# crypt: mysql/md5/bcrypt
@@ -178,4 +172,15 @@ params:
testConfig:
enabled: true
file: ./etc/testconfig.yaml
file: ./etc/testconfig.yaml
# 静态文件配置, 相对项目根路径或填绝对路径
# staticFile:
# # 默认资源dir目录需要预先创建
# default:
# prefix: "/static"
# dir: "./static"
# # 文件上传资源目录映射,与项目目录同级
# upload:
# prefix: "/upload"
# dir: "./upload"

View File

@@ -1,7 +1,7 @@
# Makefile for rest agent project
PROJECT = OMC
VERSION = 2.2403.1
VERSION = 2.2404.6
PLATFORM = amd64
ARMPLATFORM = aarch64
BUILDDIR = ../../build

View File

@@ -13,6 +13,7 @@ import (
"be.ems/features/event"
"be.ems/features/fm"
"be.ems/features/lm"
"be.ems/features/mml"
"be.ems/features/pm"
"be.ems/lib/dborm"
"be.ems/lib/global"
@@ -21,7 +22,6 @@ import (
"be.ems/restagent/config"
"be.ems/src"
"be.ems/src/framework/middleware"
libSession "be.ems/src/lib_features/session"
"github.com/gin-gonic/gin"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
@@ -197,46 +197,46 @@ func main() {
log.Infof("OMC restagent version: %s %s %s", global.Version, global.BuildTime, global.GoVer)
err := dborm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
conf.Database.Host, conf.Database.Port, conf.Database.Name)
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
if err != nil {
fmt.Println("dborm.initDbClient err:", err)
os.Exit(4)
}
err = fm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
conf.Database.Host, conf.Database.Port, conf.Database.Name)
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
if err != nil {
fmt.Println("dborm.initDbClient err:", err)
os.Exit(4)
}
err = pm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
conf.Database.Host, conf.Database.Port, conf.Database.Name)
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
if err != nil {
fmt.Println("dborm.initDbClient err:", err)
os.Exit(4)
}
err = dbrest.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
conf.Database.Host, conf.Database.Port, conf.Database.Name)
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
if err != nil {
fmt.Println("dbrest.initDbClient err:", err)
os.Exit(4)
}
err = lm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
conf.Database.Host, conf.Database.Port, conf.Database.Name)
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
if err != nil {
fmt.Println("lm.initDbClient err:", err)
os.Exit(4)
}
mml.InitMML()
// 将 mux.Router 注册到 gin.Engine
// 默认路由组
defaultUriGroup := app.Group(config.DefaultUriPrefix)
defaultUriGroup.Use(middleware.PreAuthorize(nil))
defaultUriGroup.Use(libSession.SessionHeader())
defaultUriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
// 可配置前缀路由组
uriGroup := app.Group(config.UriPrefix)
uriGroup.Use(libSession.SessionHeader())
uriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
// AMF上报的UE事件, 无前缀,暂时特殊处理
app.POST(event.UriUEEvent, event.PostUEEventFromAMF)
@@ -244,6 +244,7 @@ func main() {
// 开启监控采集
// monitor.StartMonitor(false, "")
var listenLocalhost bool = false
for _, rest := range conf.Rest {
// ipv4 goroutines
if rest.IPv4 != "" {
@@ -254,7 +255,8 @@ func main() {
go HttpListen(listen, app)
}
}
if rest.IPv4 != "0.0.0.0" {
if rest.IPv4 != "0.0.0.0" && !listenLocalhost {
listenLocalhost = true
// 默认启动localhost侦听
listenLocal := "127.0.0.1" + ":" + strconv.Itoa(int(rest.Port))
if strings.ToLower(rest.Scheme) == "https" {

View File

@@ -1,17 +0,0 @@
#! /usr/bin/bash
ps aux | grep "omcDevApp"
process_id=$(ps aux | grep "omcDevApp" | grep -v grep | awk '{print $2}')
if [ -n "$process_id" ]; then
kill -9 "$process_id"
else
echo "未找到匹配的进程"
fi
go version
go build -ldflags="-s -w" -o omcDevApp
BUILD_ID=dontKillMe
nohup ./omcDevApp -c ./dev.yaml > ./dev.log 2>&1 &
echo ok