merge: 合并OMC分支
This commit is contained in:
@@ -2,24 +2,15 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nms_cxy/lib/global"
|
||||
"nms_cxy/lib/log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/global"
|
||||
"nms_cxy/lib/log"
|
||||
|
||||
"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 {
|
||||
@@ -29,16 +20,23 @@ 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"`
|
||||
Pprof struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Addr string `yaml:"addr"`
|
||||
} `yaml:"pprof"`
|
||||
|
||||
// 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"`
|
||||
@@ -83,39 +81,9 @@ type YamlConfig struct {
|
||||
CmdTimeout int `yaml:"cmdTimeout"`
|
||||
} `yaml:"omc"`
|
||||
|
||||
Alarm struct {
|
||||
ForwardAlarm bool `yaml:"forwardAlarm"`
|
||||
Email struct {
|
||||
Smtp string `yaml:"smtp"`
|
||||
Port uint16 `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
TlsSkipVerify bool `yaml:"tlsSkipVerify"`
|
||||
} `yaml:"email"`
|
||||
SMS struct {
|
||||
ApiURL string `yaml:"apiURL"`
|
||||
AccessKeyID string `yaml:"AccessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
SignName string `yaml:"signName"`
|
||||
TemplateCode string `yaml:"templateCode"`
|
||||
} `yaml:"sms"`
|
||||
SMSC struct {
|
||||
Addr string `yaml:"addr"`
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
} `yaml:"smsc"`
|
||||
} `yaml:"alarm"`
|
||||
Alarm AlarmConfig `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"`
|
||||
@@ -156,6 +124,67 @@ 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 AlarmConfig struct {
|
||||
SplitEventAlarm bool `yaml:"splitEventAlarm"`
|
||||
ForwardAlarm bool `yaml:"forwardAlarm"`
|
||||
SMProxy string `yaml:"smProxy"`
|
||||
Email struct {
|
||||
Smtp string `yaml:"smtp"`
|
||||
Port uint16 `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
TlsSkipVerify bool `yaml:"tlsSkipVerify"`
|
||||
} `yaml:"email"`
|
||||
SMS struct {
|
||||
ApiURL string `yaml:"apiURL"`
|
||||
AccessKeyID string `yaml:"AccessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
SignName string `yaml:"signName"`
|
||||
TemplateCode string `yaml:"templateCode"`
|
||||
} `yaml:"sms"`
|
||||
SMSC struct {
|
||||
Addr string `yaml:"addr"`
|
||||
SystemID string `yaml:"systemID"`
|
||||
Password string `yaml:"password"`
|
||||
SystemType string `yaml:"systemType"`
|
||||
} `yaml:"smsc"`
|
||||
}
|
||||
|
||||
type MMLParam struct {
|
||||
Port int `yaml:"port"`
|
||||
Port2 int `yaml:"port2"`
|
||||
Sleep int64 `yaml:"sleep"`
|
||||
DeadLine int64 `yaml:"deadLine"`
|
||||
SizeRow int16 `yaml:"sizeRow"`
|
||||
SizeCol int16 `yaml:"sizeCol"`
|
||||
BufferSize int `yaml:"bufferSize"`
|
||||
User string `yaml:"user"`
|
||||
Password string `ymal:"password"`
|
||||
MmlHome string `yaml:"mmlHome"`
|
||||
}
|
||||
|
||||
type TestDatas struct {
|
||||
UDM struct {
|
||||
CapUsed uint32 `yaml:"capUsed"`
|
||||
@@ -187,7 +216,25 @@ 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: 200,
|
||||
SizeCol: 120,
|
||||
BufferSize: 65535,
|
||||
},
|
||||
Alarm: AlarmConfig{
|
||||
SplitEventAlarm: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ReadConfig(configFile string) {
|
||||
yamlFile, err := os.ReadFile(configFile)
|
||||
@@ -323,10 +370,27 @@ func ReadTestConfigYaml(pfile string) (ret error) {
|
||||
}
|
||||
|
||||
func GetDefaultUserAgent() string {
|
||||
return "OMC/" + global.Version
|
||||
return "OMC-restagent/" + global.Version
|
||||
}
|
||||
|
||||
// const defaultConfigFile = "./etc/omc.yaml"
|
||||
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() {
|
||||
// cfile := flag.String("c", defaultConfigFile, "config file")
|
||||
@@ -337,7 +401,7 @@ func GetDefaultUserAgent() string {
|
||||
// //global.GoVer = "go version go1.15.7 linux/arm64"
|
||||
// flag.Parse()
|
||||
// if *pv {
|
||||
// fmt.Printf("OMC version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
|
||||
// fmt.Printf("OMC restagent version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
|
||||
// os.Exit(0)
|
||||
// }
|
||||
// if *ph {
|
||||
|
||||
Reference in New Issue
Block a user