marge: 合并11.2版本
This commit is contained in:
1 parent
7bcb439d57
commit
e5212c47ba
88 files changed
+11678
-3054
No files matched your search
+4
-2
@@ -179,14 +179,16 @@ var ConfigFile *string
|
||||
func init() {
|
||||
ConfigFile = flag.String("c", defaultConfigFile, "config file")
|
||||
pv := flag.Bool("v", false, "print version")
|
||||
pversion := flag.Bool("version", false, "print version")
|
||||
ph := flag.Bool("h", false, "print help")
|
||||
phelp := flag.Bool("help", false, "print help")
|
||||
|
||||
flag.Parse()
|
||||
if *pv {
|
||||
if *pv || *pversion {
|
||||
fmt.Printf("OMC crontask version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
|
||||
os.Exit(0)
|
||||
}
|
||||
if *ph {
|
||||
if *ph || *phelp {
|
||||
flag.Usage()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# level: /trace/debug/info/error/warn/error/fatal, default: debug
|
||||
# duration: saved days, default is 30 days
|
||||
logger:
|
||||
file: d:/local.git/be.ems/crontask/log/crontask.log
|
||||
file: d:/omc.git/be.ems/crontask/log/crontask.log
|
||||
level: trace
|
||||
duration: 24
|
||||
count: 10
|
||||
@@ -26,7 +26,7 @@ database:
|
||||
port: 33066
|
||||
name: omc_db
|
||||
connParam: charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True
|
||||
backup: d:/local.git/be.ems/restagent/database
|
||||
backup: d:/omc.git/be.ems/restagent/database
|
||||
|
||||
# northbound interface, cm/pm
|
||||
# duration(day): saved days
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Makefile for OMC-OMC-crontask project
|
||||
|
||||
PROJECT = OMC
|
||||
VERSION = 2.2408.1
|
||||
VERSION = 2.2411.2
|
||||
LIBDIR = be.ems/lib
|
||||
BINNAME = crontask
|
||||
|
||||
|
||||
+75
-76
@@ -18,7 +18,6 @@ import (
|
||||
"be.ems/lib/log"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/shirou/gopsutil/process"
|
||||
|
||||
// cron "github.com/go-co-op/gocron"
|
||||
"github.com/jasonlvhit/gocron"
|
||||
@@ -1456,82 +1455,82 @@ func init() {
|
||||
|
||||
func (t *TaskFunc) TaskWriteSystemLog(uri, params, body string) {
|
||||
|
||||
processes, err := process.Processes()
|
||||
if err != nil {
|
||||
log.Error("Failed to get processes:", err)
|
||||
return
|
||||
}
|
||||
// processes, err := process.Processes()
|
||||
// if err != nil {
|
||||
// log.Error("Failed to get processes:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
for _, proc := range processes {
|
||||
name, err := proc.Name()
|
||||
if err != nil {
|
||||
log.Error("Failed to get process name:", err)
|
||||
continue
|
||||
}
|
||||
for i, procInfo := range procInfos {
|
||||
if name == procInfo.Name {
|
||||
pid := proc.Pid
|
||||
timestamp, _ := proc.CreateTime()
|
||||
userName, _ := proc.Username()
|
||||
startTime := time.Unix((timestamp / 1000), 0).Format(time.DateTime)
|
||||
// for _, proc := range processes {
|
||||
// name, err := proc.Name()
|
||||
// if err != nil {
|
||||
// log.Error("Failed to get process name:", err)
|
||||
// continue
|
||||
// }
|
||||
// for i, procInfo := range procInfos {
|
||||
// if name == procInfo.Name {
|
||||
// pid := proc.Pid
|
||||
// timestamp, _ := proc.CreateTime()
|
||||
// userName, _ := proc.Username()
|
||||
// startTime := time.Unix((timestamp / 1000), 0).Format(time.DateTime)
|
||||
|
||||
newProcInfo := &ProcInfo{
|
||||
Name: procInfo.Name,
|
||||
Pid: pid,
|
||||
StartTime: startTime,
|
||||
}
|
||||
log.Trace("newProcInfo:", *newProcInfo)
|
||||
log.Trace("procInfo:", procInfo)
|
||||
if *newProcInfo != procInfo {
|
||||
procInfos[i] = *newProcInfo
|
||||
var operation string
|
||||
if newProcInfo.Pid != 0 {
|
||||
operation = "start"
|
||||
} else {
|
||||
operation = "stop"
|
||||
}
|
||||
sysLogs := &[]dborm.SystemLog{}
|
||||
sysLog := &dborm.SystemLog{
|
||||
UserName: userName,
|
||||
ProcessName: newProcInfo.Name,
|
||||
ProcessID: newProcInfo.Pid,
|
||||
Operation: operation,
|
||||
StartTime: newProcInfo.StartTime,
|
||||
LogTime: time.Now().Format(time.DateTime),
|
||||
}
|
||||
var response *resty.Response
|
||||
requestURI := fmt.Sprintf("%s?%s", uri, params)
|
||||
requestURL := fmt.Sprintf("%s%s", yamlConfig.OMC.HostUri, requestURI)
|
||||
// newProcInfo := &ProcInfo{
|
||||
// Name: procInfo.Name,
|
||||
// Pid: pid,
|
||||
// StartTime: startTime,
|
||||
// }
|
||||
// log.Trace("newProcInfo:", *newProcInfo)
|
||||
// log.Trace("procInfo:", procInfo)
|
||||
// if *newProcInfo != procInfo {
|
||||
// procInfos[i] = *newProcInfo
|
||||
// var operation string
|
||||
// if newProcInfo.Pid != 0 {
|
||||
// operation = "start"
|
||||
// } else {
|
||||
// operation = "stop"
|
||||
// }
|
||||
// sysLogs := &[]dborm.SystemLog{}
|
||||
// sysLog := &dborm.SystemLog{
|
||||
// UserName: userName,
|
||||
// ProcessName: newProcInfo.Name,
|
||||
// ProcessID: newProcInfo.Pid,
|
||||
// Operation: operation,
|
||||
// StartTime: newProcInfo.StartTime,
|
||||
// LogTime: time.Now().Format(time.DateTime),
|
||||
// }
|
||||
// var response *resty.Response
|
||||
// requestURI := fmt.Sprintf("%s?%s", uri, params)
|
||||
// requestURL := fmt.Sprintf("%s%s", yamlConfig.OMC.HostUri, requestURI)
|
||||
|
||||
*sysLogs = append(*sysLogs, *sysLog)
|
||||
data := make(map[string]interface{})
|
||||
data["system_log"] = *sysLogs
|
||||
body, _ := json.Marshal(data)
|
||||
log.Trace("data:", data)
|
||||
log.Debug("requestURL: POST ", 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"}).
|
||||
SetBody(body).
|
||||
Post(requestURL)
|
||||
if err != nil {
|
||||
log.Error("Failed to post:", 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.Debug("response body:", string(response.Body()))
|
||||
body := new(map[string]interface{})
|
||||
_ = json.Unmarshal(response.Body(), &body)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// *sysLogs = append(*sysLogs, *sysLog)
|
||||
// data := make(map[string]interface{})
|
||||
// data["system_log"] = *sysLogs
|
||||
// body, _ := json.Marshal(data)
|
||||
// log.Trace("data:", data)
|
||||
// log.Debug("requestURL: POST ", 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"}).
|
||||
// SetBody(body).
|
||||
// Post(requestURL)
|
||||
// if err != nil {
|
||||
// log.Error("Failed to post:", 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.Debug("response body:", string(response.Body()))
|
||||
// body := new(map[string]interface{})
|
||||
// _ = json.Unmarshal(response.Body(), &body)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user