dd
This commit is contained in:
@@ -138,7 +138,14 @@ tasks:
|
||||
interval: 5
|
||||
unit: Seconds
|
||||
at:
|
||||
do: TaskWriteSystemLog
|
||||
do: TaskWriteSystemLog
|
||||
- name: Copy log to /opt/omc/ftp/log
|
||||
uri:
|
||||
params: cp -rf /usr/local/omc/database/*.csv /opt/omc/ftp/log
|
||||
interval: 10
|
||||
unit: Minutes
|
||||
at:
|
||||
do: TaskRunShellCommand
|
||||
# - name: Import CM to NF
|
||||
# uri: /api/rest/systemManagement/v1/elementType/udm/objectType/cm
|
||||
# params: ne_id=SZ_01
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -305,6 +306,74 @@ func (t *TaskFunc) TaskDBBackupCSVGetBySQL(uri, params, body string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TaskFunc) TaskRunShellCommand(uri, params, body string) {
|
||||
log.Debug("TaskUpdateTable processing... ")
|
||||
|
||||
var output []byte
|
||||
var str string
|
||||
cmd := exec.Command("/bin/bash", "-c", params)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("exe cmd error: ", err)
|
||||
str := fmt.Sprintf("Command: %s output:\n\n%v\n", params, string(out))
|
||||
//output = *ParseErrorOutput(err)
|
||||
output = []byte(str)
|
||||
//return &output
|
||||
} else {
|
||||
str := fmt.Sprintf("Command: %s output:\n\n%v\n", params, string(out))
|
||||
output = []byte(str)
|
||||
}
|
||||
|
||||
log.Trace("str: ", str)
|
||||
log.Trace("output:", output)
|
||||
}
|
||||
|
||||
func (t *TaskFunc) TaskRunShellCommand(uri, params, body string) {
|
||||
log.Debug("TaskRunShellCommand processing... ")
|
||||
|
||||
cmd := exec.Command("/bin/bash", "-c", command)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("exe cmd error: ", err)
|
||||
str := fmt.Sprintf("Command: %s output:\n\n%v\n", command, string(out))
|
||||
//output = *ParseErrorOutput(err)
|
||||
output = []byte(str)
|
||||
//return &output
|
||||
} else {
|
||||
str := fmt.Sprintf("Command: %s output:\n\n%v\n", command, string(out))
|
||||
output = []byte(str)
|
||||
}
|
||||
|
||||
var response *resty.Response
|
||||
tableName := t.GetTableNameFromUri(uri)
|
||||
filePath := fmt.Sprintf("%s/%s-%s.csv", GetYamlConfig().Database.Backup, tableName, time.Now().Local().Format(global.DateData))
|
||||
pa := fmt.Sprintf(params, filePath)
|
||||
requestURI := fmt.Sprintf("%s?%s", uri, pa)
|
||||
requestURL := fmt.Sprintf("%s%s", yamlConfig.OMC.HostUri, requestURI)
|
||||
log.Debug("requestURL: Get ", requestURL)
|
||||
client := resty.New()
|
||||
response, err := client.R().
|
||||
EnableTrace().
|
||||
SetHeaders(map[string]string{"User-Agent": GetDefaultUserAgent()}).
|
||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||
Get(requestURL)
|
||||
if err != nil {
|
||||
log.Error("Failed to Get:", err)
|
||||
}
|
||||
|
||||
log.Debug("StatusCode: ", response.StatusCode())
|
||||
switch response.StatusCode() {
|
||||
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
|
||||
log.Debug("response body:", string(response.Body()))
|
||||
body := new(map[string]interface{})
|
||||
_ = json.Unmarshal(response.Body(), &body)
|
||||
default:
|
||||
log.Error("response body:", string(response.Body()))
|
||||
}
|
||||
}
|
||||
|
||||
type CpuUsage struct {
|
||||
NfCpuUsage uint16 `json:"nfCpuUsage"`
|
||||
SysCpuUsage uint16 `json:"sysCpuUsage"`
|
||||
|
||||
Reference in New Issue
Block a user