Plugin collect support stdin and env
This commit is contained in:
parent
ea25842f9d
commit
0d2860dd8e
2
control
2
control
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# release version
|
||||
version=2.2.2
|
||||
version=2.3.0
|
||||
|
||||
CWD=$(cd $(dirname $0)/; pwd)
|
||||
cd $CWD
|
||||
|
|
|
@ -263,6 +263,8 @@ CREATE TABLE `plugin_collect` (
|
|||
`step` int(11) NOT NULL DEFAULT '0' COMMENT '采集周期',
|
||||
`file_path` varchar(255) NOT NULL COMMENT 'file_path',
|
||||
`params` varchar(255) NOT NULL COMMENT 'params',
|
||||
`stdin` text NOT NULL COMMENT 'stdin',
|
||||
`env` text NOT NULL COMMENT 'env',
|
||||
`comment` varchar(512) NOT NULL DEFAULT '' COMMENT 'comment',
|
||||
`creator` varchar(255) NOT NULL DEFAULT '' COMMENT 'creator',
|
||||
`created` datetime NOT NULL COMMENT 'created',
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
use n9e_mon;
|
||||
ALTER TABLE plugin_collect ADD stdin text AFTER params;
|
||||
ALTER TABLE plugin_collect ADD env text AFTER params;
|
|
@ -141,6 +141,8 @@ type PluginCollect struct {
|
|||
Step int `json:"step"`
|
||||
FilePath string `json:"file_path"`
|
||||
Params string `json:"params"`
|
||||
Stdin string `json:"stdin"`
|
||||
Env string `json:"env"`
|
||||
Comment string `json:"comment"`
|
||||
Creator string `json:"creator"`
|
||||
Created time.Time `xorm:"updated" json:"created"`
|
||||
|
|
|
@ -224,10 +224,7 @@ func (w *Worker) producer(line string, strategy *stra.Strategy) (*AnalysPoint, e
|
|||
t = reg.ReplaceAllString(t, rep)
|
||||
}
|
||||
|
||||
// [风险]统一使用东八区
|
||||
// loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
loc := time.FixedZone("CST", 8*3600)
|
||||
tms, err := time.ParseInLocation(timeFormat, t, loc)
|
||||
tms, err := time.Parse(timeFormat, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package plugins
|
|||
type Plugin struct {
|
||||
FilePath string
|
||||
Params string
|
||||
Env string
|
||||
Stdin string
|
||||
MTime int64
|
||||
Cycle int
|
||||
}
|
||||
|
|
|
@ -30,12 +30,13 @@ func ListPluginsFromMonapi() map[string]*Plugin {
|
|||
plugins := stra.Collect.GetPlugin()
|
||||
|
||||
for key, p := range plugins {
|
||||
fpath := p.FilePath
|
||||
plugin := &Plugin{
|
||||
FilePath: fpath,
|
||||
FilePath: p.FilePath,
|
||||
MTime: p.LastUpdated.Unix(),
|
||||
Cycle: p.Step,
|
||||
Params: p.Params,
|
||||
Env: p.Env,
|
||||
Stdin: p.Stdin,
|
||||
}
|
||||
|
||||
ret[key] = plugin
|
||||
|
|
|
@ -62,9 +62,27 @@ func PluginRun(plugin *Plugin) {
|
|||
cmd := exec.Command(fpath, params...)
|
||||
cmd.Dir = filepath.Dir(fpath)
|
||||
var stdout bytes.Buffer
|
||||
|
||||
cmd.Stdout = &stdout
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if plugin.Stdin != "" {
|
||||
cmd.Stdin = bytes.NewReader([]byte(plugin.Stdin))
|
||||
}
|
||||
|
||||
if plugin.Env != "" {
|
||||
envs := []string{}
|
||||
err := json.Unmarshal([]byte(plugin.Env), &envs)
|
||||
if err != nil {
|
||||
logger.Errorf("plugin:%+v %v", plugin, err)
|
||||
return
|
||||
}
|
||||
for _, env := range envs {
|
||||
cmd.Env = append(cmd.Env, env)
|
||||
}
|
||||
}
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
|
|
Loading…
Reference in New Issue