diff --git a/features/sm/backup.go b/features/sm/backup.go index ffb70510..3cd09af4 100644 --- a/features/sm/backup.go +++ b/features/sm/backup.go @@ -3,15 +3,51 @@ package sm import ( "database/sql" "fmt" + "net/http" "os" "os/exec" "time" "ems.agt/lib/log" + "ems.agt/lib/services" "ems.agt/restagent/config" _ "github.com/go-sql-driver/mysql" ) +var ( + // Get OMC local time + UriOMCLocalTime = config.DefaultUriPrefix + "systemManagement/{apiVersion}/elementType/OMC/objectType/time" + + CustomUriOMCLocalTime = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/OMC/objectType/time" +) + +type OMCLocalTime struct { + Timestamp int64 `json:"timestamp"` // 时间戳 (单位:毫秒) + TimeZone int `json:"timeZone"` // 本地时区偏移(单位:秒) +} + +func GetOMCLocalTime(w http.ResponseWriter, r *http.Request) { + log.Debug("GetOMCLocalTime processing... ") + + _, err := services.CheckFrontValidRequest(w, r) + if err != nil { + log.Error("Http request error:", err) + return + } + + t := time.Now() + _, offset := t.Zone() + + localTime := OMCLocalTime{ + Timestamp: t.UnixMilli(), + TimeZone: offset, + } + response := services.DataResponse{ + Data: localTime, + } + services.ResponseWithJson(w, http.StatusOK, response) +} + var dbConfig = config.GetYamlConfig().Database func DatabaseWhoreBackup() { diff --git a/lib/routes/routes.go b/lib/routes/routes.go index b0e187e2..9ab9299b 100644 --- a/lib/routes/routes.go +++ b/lib/routes/routes.go @@ -17,6 +17,7 @@ import ( "ems.agt/features/nbi" "ems.agt/features/pm" "ems.agt/features/security" + "ems.agt/features/sm" "ems.agt/features/state" sysconfig "ems.agt/features/sys_config" sysdictdata "ems.agt/features/sys_dict_data" @@ -66,6 +67,9 @@ func init() { Register("GET", state.CustomUriLicenseInfoAll, state.GetAllLicenseInfoFromNF, nil) Register("GET", state.CustomUriLicenseInfoOne, state.GetOneLicenseInfoFromNF, nil) + Register("GET", sm.UriOMCLocalTime, sm.GetOMCLocalTime, nil) + Register("GET", sm.CustomUriOMCLocalTime, sm.GetOMCLocalTime, nil) + // 数据库直连操作权限 selectPermission := midware.Authorize(map[string][]string{ "hasRoles": {"dba"}, diff --git a/restagent/config/config.go b/restagent/config/config.go index 77a543ae..92ad9b2b 100644 --- a/restagent/config/config.go +++ b/restagent/config/config.go @@ -319,8 +319,8 @@ func init() { pv := flag.Bool("version", false, "print version") ph := flag.Bool("help", false, "print help") - global.BuildTime = "Wed May 31 18:24:04 CST 2023" - global.GoVer = "go version go1.15.7 linux/arm64" + //global.BuildTime = "Wed May 31 18:24:04 CST 2023" + //global.GoVer = "go version go1.15.7 linux/arm64" flag.Parse() if *pv { fmt.Printf("OMC restagent version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)