config
This commit is contained in:
@@ -79,7 +79,7 @@ omc:
|
|||||||
alias: "ne_type"
|
alias: "ne_type"
|
||||||
type: "string"
|
type: "string"
|
||||||
optional: "true"
|
optional: "true"
|
||||||
apostr: "false"
|
apostr: "true"
|
||||||
filter: ""
|
filter: ""
|
||||||
display: "NE type"
|
display: "NE type"
|
||||||
comment: ""
|
comment: ""
|
||||||
@@ -87,6 +87,7 @@ omc:
|
|||||||
alias: "ne_id"
|
alias: "ne_id"
|
||||||
type: "string"
|
type: "string"
|
||||||
optional: "true"
|
optional: "true"
|
||||||
|
apostr: "true"
|
||||||
filter: ""
|
filter: ""
|
||||||
display: "NE ID"
|
display: "NE ID"
|
||||||
comment: ""
|
comment: ""
|
||||||
@@ -98,7 +99,7 @@ omc:
|
|||||||
alias: "ne_type"
|
alias: "ne_type"
|
||||||
type: "string"
|
type: "string"
|
||||||
optional: "false"
|
optional: "false"
|
||||||
apostr: "false"
|
apostr: "true"
|
||||||
filter: ""
|
filter: ""
|
||||||
display: "Source NE type"
|
display: "Source NE type"
|
||||||
comment: ""
|
comment: ""
|
||||||
|
|||||||
@@ -196,20 +196,11 @@ func ExtDatabaseExecSQL(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
vars := mux.Vars(r)
|
//vars := mux.Vars(r)
|
||||||
tblName := vars["dataObject"]
|
//tblName := vars["dataObject"]
|
||||||
sql = GetUriSQLArray(r)
|
sql = GetUriSQLArray(r)
|
||||||
// select as must, todo ...
|
// select as must, todo ...
|
||||||
|
|
||||||
if sql == nil {
|
|
||||||
wc := services.GetUriLocString(r)
|
|
||||||
if wc == "" {
|
|
||||||
sql = append(sql, fmt.Sprintf("select * from %s", tblName))
|
|
||||||
} else {
|
|
||||||
sql = append(sql, fmt.Sprintf("select * from %s where %s", tblName, wc))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ls := services.ExtGetUriPageLimitString(r)
|
ls := services.ExtGetUriPageLimitString(r)
|
||||||
|
|
||||||
// data := make([]map[string]interface{}, 0)
|
// data := make([]map[string]interface{}, 0)
|
||||||
@@ -219,7 +210,7 @@ func ExtDatabaseExecSQL(w http.ResponseWriter, r *http.Request) {
|
|||||||
for i, s := range sql {
|
for i, s := range sql {
|
||||||
log.Tracef("SQL[%d]: %s", i, sql[i])
|
log.Tracef("SQL[%d]: %s", i, sql[i])
|
||||||
|
|
||||||
rows := make([]map[string]interface{}, 0)
|
//rows := make([]map[string]interface{}, 0)
|
||||||
mapRows := make(map[string]interface{})
|
mapRows := make(map[string]interface{})
|
||||||
|
|
||||||
if s != "" {
|
if s != "" {
|
||||||
@@ -234,7 +225,7 @@ func ExtDatabaseExecSQL(w http.ResponseWriter, r *http.Request) {
|
|||||||
querySQL = querySQL + " " + ls
|
querySQL = querySQL + " " + ls
|
||||||
}
|
}
|
||||||
log.Debug("querySQL:", querySQL)
|
log.Debug("querySQL:", querySQL)
|
||||||
rows, err = DbClient.XEngine.QueryInterface(querySQL)
|
rows, err := DbClient.XEngine.Exec(querySQL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SQL failed:", err)
|
log.Error("SQL failed:", err)
|
||||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||||
|
|||||||
134
features/lm/logbak.go
Normal file
134
features/lm/logbak.go
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package dbrest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"ems.agt/lib/dborm"
|
||||||
|
"ems.agt/lib/log"
|
||||||
|
"ems.agt/lib/services"
|
||||||
|
"ems.agt/restagent/config"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type XormResponse struct {
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XormInsertResponse struct {
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ExtBackupDataUri = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/{dataStorage}/{dataObject}/backup" // for external
|
||||||
|
|
||||||
|
CustomExtBackupDataUri = config.UriPrefix + "/dataManagement/{apiVersion}/{dataStorage}/{dataObject}/backup" // for external
|
||||||
|
)
|
||||||
|
|
||||||
|
var XEngine *xorm.Engine
|
||||||
|
|
||||||
|
type DatabaseClient struct {
|
||||||
|
dbType string
|
||||||
|
dbUrl string
|
||||||
|
dbConnMaxLifetime time.Duration
|
||||||
|
dbMaxIdleConns int
|
||||||
|
dbMaxOpenConns int
|
||||||
|
IsShowSQL bool
|
||||||
|
|
||||||
|
XEngine *xorm.Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
var DbClient DatabaseClient
|
||||||
|
|
||||||
|
func InitDbClient(dbType, dbUser, dbPassword, dbHost, dbPort, dbName string) error {
|
||||||
|
DbClient.dbUrl = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=true&loc=Local",
|
||||||
|
dbUser, dbPassword, dbHost, dbPort, dbName)
|
||||||
|
DbClient.dbType = dbType
|
||||||
|
DbClient.dbConnMaxLifetime = 0
|
||||||
|
DbClient.dbMaxIdleConns = 0
|
||||||
|
DbClient.dbMaxOpenConns = 0
|
||||||
|
if log.GetLevel() == log.LOG_TRACE {
|
||||||
|
DbClient.IsShowSQL = true
|
||||||
|
}
|
||||||
|
log.Debugf("dbType:%s dbUrl:%s:******@tcp(%s:%s)/%s??charset=utf8&parseTime=true&loc=Local",
|
||||||
|
dbType, dbUser, dbHost, dbPort, dbName)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
DbClient.XEngine, err = xorm.NewEngine(DbClient.dbType, DbClient.dbUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to connet database:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
DbClient.XEngine.SetConnMaxLifetime(DbClient.dbConnMaxLifetime)
|
||||||
|
DbClient.XEngine.SetMaxIdleConns(DbClient.dbMaxIdleConns)
|
||||||
|
DbClient.XEngine.SetMaxOpenConns(DbClient.dbMaxOpenConns)
|
||||||
|
if DbClient.IsShowSQL {
|
||||||
|
DbClient.XEngine.ShowSQL(true)
|
||||||
|
}
|
||||||
|
XEngine = DbClient.XEngine
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExtDatabaseBackupData(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Debug("ExtDatabaseBackupData processing... ")
|
||||||
|
|
||||||
|
token, err := services.CheckExtValidRequest(w, r)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Request error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
dbname := vars["dataStorage"]
|
||||||
|
tbname := vars["dataObject"]
|
||||||
|
|
||||||
|
log.Debugf("token:%s, method:%s, dbname:%s, tbname:%s", token, r.Method, dbname, tbname)
|
||||||
|
exist, err := services.CheckUserPermission(token, strings.ToLower(r.Method), dbname, tbname)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to get permission:", err)
|
||||||
|
services.ResponseForbidden403NotPermission(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !exist {
|
||||||
|
log.Error("permission deny!")
|
||||||
|
services.ResponseForbidden403NotPermission(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var sql string
|
||||||
|
switch tbname {
|
||||||
|
case "operation_log":
|
||||||
|
filePath := fmt.Sprintf("%s/%s-%s.csv", GetYamlConfig().Database.Backup, tableName, time.Now().Local().Format(global.DateData))
|
||||||
|
sql = fmt.Sprintf("select * into outfile '%s' fields terminated by ',' escaped by '' optionally enclosed by '' lines terminated by '\n' from (select 'op_id','account_name','op_ip','subsys_tag','op_type','op_content','op_result','begin_time','end_time','vnf_flag','log_time' union select op_id,account_name,op_ip,subsys_tag,op_type,op_content,op_result,begin_time,end_time,vnf_flag,log_time from operation_log) b
|
||||||
|
", filePath)
|
||||||
|
case "secrurity_log":
|
||||||
|
filePath := fmt.Sprintf("%s/%s-%s.csv", GetYamlConfig().Database.Backup, tableName, time.Now().Local().Format(global.DateData))
|
||||||
|
sql = fmt.Sprintf("select * into outfile '%s' fields terminated by ',' escaped by '' optionally enclosed by '' lines terminated by '\n' from (select 'id','account_name','account_type','op_ip','op_type','op_content','op_result','op_time' union select id,account_name,account_type,op_ip,op_type,op_content,op_result,op_time from security_log) b", filePath)
|
||||||
|
case "alarm_log":
|
||||||
|
filePath := fmt.Sprintf("%s/%s-%s.csv", GetYamlConfig().Database.Backup, tableName, time.Now().Local().Format(global.DateData))
|
||||||
|
sql = fmt.Sprintf("select * into outfile 'd:/local.git/be.ems/restagent/database/alarm-log-1.csv' fields terminated by ',' escaped by '' optionally enclosed by '' lines terminated by '\n' from (select 'id','ne_type','ne_id','alarm_seq','alarm_id','alarm_code','alarm_status','event_time','log_time' union select id,ne_type,ne_id,alarm_seq,alarm_id,alarm_code,alarm_status,event_time,log_time from alarm_log) b", filePath)
|
||||||
|
default:
|
||||||
|
log.Error("error target tale")
|
||||||
|
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := DbClient.XEngine.Exec(sql)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to exec SQL:", err)
|
||||||
|
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
n, _ := res.RowsAffected()
|
||||||
|
affected = affected + n
|
||||||
|
|
||||||
|
mapRow := make(map[string]interface{})
|
||||||
|
row := map[string]interface{}{"affectedRows": affected}
|
||||||
|
mapRow[tn] = row
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, mapRow)
|
||||||
|
}
|
||||||
@@ -15,5 +15,5 @@ database:
|
|||||||
name: omc_db
|
name: omc_db
|
||||||
|
|
||||||
mml:
|
mml:
|
||||||
filedir: ../../config/mml/system
|
filedir: ../../config/mml/omc
|
||||||
table: mml_system
|
table: mml_command
|
||||||
|
|||||||
Reference in New Issue
Block a user