Skip to content

Commit ad3fcd3

Browse files
committed
fix log agent
1 parent 69d69ff commit ad3fcd3

File tree

7 files changed

+58
-48
lines changed

7 files changed

+58
-48
lines changed

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Intor Oneaction
22
oneaction
33

4+
#install lua
5+
apt-get install libncurses5-dev
6+
7+
https://www.lua.org/ftp/ lua-5.1.5.tar.gz
8+
9+
make linux && make install
10+
411
# Install dir & work dir:
512

613
you can configure the work dir for oneaction in config/config.go like this:
@@ -9,6 +16,7 @@ oneaction
916
for example the work dir is /data/oneflow/, so you should copy pkg dir which is in this project
1017
to the work dir, or just make a link from pkg dir to the work dir. just like this:
1118
ln -s /home/helight/oneaction/pkg /data/oneflow
19+
ln -s /home/helight/oneaction/web /home/helight/www/
1220

1321
# Config
1422
## workdir
@@ -30,6 +38,10 @@ to the work dir, or just make a link from pkg dir to the work dir. just like thi
3038
db_name = flag.String("db_name", "aflow", "mysql server name")
3139
)
3240

41+
create database aflow;
42+
create user 'admin'@'localhost' IDENTIFIED BY 'mysql';
43+
grant all privileges on aflow.* to admin@localhost identified by 'mysql';
44+
3345
## server work port
3446
config/server.go
3547
ServerHost = flag.String("server_host", helper.GetIPAddr(), "Host of flow server.")
@@ -61,11 +73,14 @@ to the work dir, or just make a link from pkg dir to the work dir. just like thi
6173
values ("222", 1, "223","127.0.0.1","223db", 1);
6274
insert into tbServer(`host`,`port`,`username`,`password`) values ("127.0.0.1", 22, "helight", "helight");
6375
insert into tbServer(`host`,`port`,`username`,`password`) values ("10.0.2.15", 22, "helight", "helight");
76+
insert into tbServer(`host`,`port`,`username`,`password`) values ("172.22.112.56", 22, "helight", "helight");
77+
78+
ERROR:ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
6479

6580
# lua demo
6681
put those lua script to the task and run it, first you should have the shell script in this lua script.
6782

6883
print("123")
69-
puuid, output=gassert(remote_exec("127.0.0.1", "/data/actionflow/bin/script/test.sh", "222"))
84+
puuid, output=gassert(remote_exec("127.0.0.1", "/data/oneflow/bin/script/test.sh", "222"))
7085
print("Process UUID:"..puuid)
7186
print("Remote exec output:"..output)

pkg/bin/script/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ ls /
44

55
sleep 5
66

7-
ls /data/actionflow/
7+
ls /usr/

src/lua_helper/lua_helper.go

+14-30
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import (
1111
log "github.com/cihub/seelog"
1212
)
1313

14-
// var (
15-
// LuaGlobal = luar.Map{}
16-
// LuaPackages = make(map[string]luar.Map)
17-
// )
18-
1914
type iState struct {
2015
*lua.LState
2116
writer io.Writer
@@ -34,22 +29,7 @@ func (l *iState) iRegister() {
3429
log.Info("Do Register ")
3530
fmt.Println("Do Register ")
3631
l.Remote_init(l.LState)
37-
// funcs := luar.Map{}
38-
// for name, fun := range LuaGlobal {
39-
// funcs[name] = fun
40-
// }
41-
//
42-
// lval := reflect.ValueOf(l)
43-
// ltype := reflect.TypeOf(l)
44-
// for i := 0; i < ltype.NumMethod(); i++ {
45-
// method := ltype.Method(i)
46-
// if strings.HasPrefix(method.Name, "Lua_") {
47-
// fun_name := strings.TrimPrefix(method.Name, "Lua_")
48-
// log.Info("Register ", fun_name)
49-
// funcs[fun_name] = lval.MethodByName(method.Name).Interface()
50-
// }
51-
// }
52-
// luar.Register(l.State, "", funcs)
32+
5333
}
5434

5535
func (l *iState) GetOutput() string {
@@ -66,7 +46,6 @@ func GetStateByPId(pid string) *iState {
6646

6747
func GetState() *iState {
6848
L := &iState{}
69-
// L.State = luar.Init()
7049
L.LState = lua.NewState()
7150
L.RemoteExecRecords = make([]*RemoteExecRec, 0)
7251
L.RemoteExecUseRoot = true
@@ -76,14 +55,9 @@ func GetState() *iState {
7655
L.OpenLibs()
7756
L.iRegister()
7857
L.Register("gassert", assert)
79-
// L.Register("print", L.print)
80-
// luar.Register(L.State, "", luar.Map{
81-
// "pprint": L.pprint,
82-
// })
83-
//
84-
// for pkgname, pkgcontent := range LuaPackages {
85-
// luar.Register(L.State, pkgname, pkgcontent)
86-
// }
58+
L.Register("print", L.print)
59+
// L.SetGlobal("print", L.NewFunction(l.print))
60+
8761
return L
8862
}
8963

@@ -106,3 +80,13 @@ func (s *iState) GetRemoteTaskCount() int {
10680
return s.remote_task_count
10781
}
10882

83+
func (l *iState) print(L *lua.LState) int {
84+
top := L.GetTop()
85+
for i := 1; i <= top; i++ {
86+
lv := L.Get(i)
87+
l.writer.Write(([]byte)(lv.String()))
88+
l.writer.Write(([]byte)(" "))
89+
}
90+
l.writer.Write(([]byte)("\n"))
91+
return 0
92+
}

src/lua_helper/remote.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"code.google.com/p/uuid"
2525
"github.com/yuin/gopher-lua"
26+
// "layeh.com/gopher-luar"
2627
log "github.com/cihub/seelog"
2728
"golang.org/x/crypto/ssh"
2829
)
@@ -124,9 +125,14 @@ func (l *iState) Lua_remote_exec(L *lua.LState) int {
124125
}
125126
}
126127
guid, output, err := l.remote_exec(host, program, args)
128+
L.Push(lua.LString(guid))
129+
L.Push(lua.LString(output))
130+
// L.SetGlobal("guid", lua.LString(guid))
131+
// L.SetGlobal("output", lua.LString(output))
132+
// L.SetGlobal("err", lua.LString(err))
127133
fmt.Println("xxx guid: ", guid, " output: ", output, " err: ", err)
128134

129-
return 0;
135+
return 2;
130136
}
131137

132138
func (l *iState) remote_exec(host string, program string, args ...interface{}) (guid string, output string, err error) {

src/makefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export GOPATH=$(shell pwd)/../:$(shell pwd)/../go-package/
22
export CC=gcc -no-pie
33

44
go1.4=/usr/local/go1.4/bin/go
5-
go1.11=/usr/local/go1.11/bin/go
5+
#go1.11=/usr/local/go1.11/bin/go
6+
go1.11=go
67

78
FServer=flow_server
89
FAgent=task_agent/flow_agent
@@ -12,20 +13,20 @@ FAgent=task_agent/flow_agent
1213

1314
all: server agent
1415

15-
server:export GOROOT=/usr/local/go1.11/
16+
#server:export GOROOT=/usr/local/go1.11/
1617
server:
1718
$(go1.11) build -o $(FServer) flow_server.go
1819
cp $(FServer) ../pkg/bin/
1920

20-
agent:export GOROOT=/usr/local/go1.11/
21+
#agent:export GOROOT=/usr/local/go1.11/
2122
agent:
2223
$(go1.11) build -o app/client app/client.go
2324
$(go1.11) build -o app/luar_demo app/luar_demo.go
2425
$(go1.11) build -o app/microtest app/microtest.go
2526
$(go1.11) build -o $(FAgent) task_agent/main.go
2627
cp $(FAgent) ../pkg/bin/
2728

28-
test:export GOROOT=/usr/local/go1.11/
29+
#test:export GOROOT=/usr/local/go1.11/
2930
test:
3031
# $(go1.11) test -v lua_helper/lua_test.go lua_helper/lua_helper.go lua_helper/remote.go
3132
$(go1.11) test -v scheduler/parser.go scheduler/parser_test.go scheduler/spec.go

web/actionflow.sql

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CREATE TABLE `tbProducts` (
2121
`DBName` varchar(50) DEFAULT '0',
2222
`StarLevel` int(11) NOT NULL DEFAULT '0',
2323
PRIMARY KEY (`PId`)
24-
) ENGINE=InnoDB DEFAULT CHARSET=utf8
24+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2525

2626
-- Create syntax for TABLE 'tbAccessFlowLog'
2727
CREATE TABLE `tbAccessFlowLog` (
@@ -36,7 +36,7 @@ CREATE TABLE `tbAccessFlowLog` (
3636
`log_time` datetime DEFAULT NULL,
3737
PRIMARY KEY (`id`),
3838
KEY `flow_name` (`pid`,`flow_id`,`log_date`)
39-
) ENGINE=InnoDB AUTO_INCREMENT=11295 DEFAULT CHARSET=utf8;
39+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4040

4141
-- Create syntax for TABLE 'tbFlow'
4242
CREATE TABLE `tbFlow` (
@@ -85,7 +85,7 @@ CREATE TABLE `tbFlowSchdRunLog` (
8585
`end_time` datetime NOT NULL,
8686
`result` int(11) NOT NULL,
8787
PRIMARY KEY (`id`)
88-
) ENGINE=InnoDB AUTO_INCREMENT=222353 DEFAULT CHARSET=utf8;
88+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
8989

9090
-- Create syntax for TABLE 'tbFlowInst'
9191
CREATE TABLE `tbFlowInst` (
@@ -105,7 +105,7 @@ CREATE TABLE `tbFlowInst` (
105105
`end_task` varchar(50) NOT NULL DEFAULT '',
106106
PRIMARY KEY (`id`),
107107
UNIQUE KEY `flow_id` (`flow_id`,`pid`,`key`,`running_day`)
108-
) ENGINE=InnoDB AUTO_INCREMENT=7726990 DEFAULT CHARSET=utf8;
108+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
109109

110110
-- Create syntax for TABLE 'tbJobRunLog'
111111
CREATE TABLE `tbJobRunLog` (
@@ -118,7 +118,7 @@ CREATE TABLE `tbJobRunLog` (
118118
`end_time` datetime NOT NULL,
119119
`result` int(11) NOT NULL,
120120
PRIMARY KEY (`id`)
121-
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8;
121+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
122122

123123
-- Create syntax for TABLE 'tbJobSchedule'
124124
CREATE TABLE `tbJobSchedule` (
@@ -135,7 +135,7 @@ CREATE TABLE `tbJobSchedule` (
135135
`last_result` int(11) NOT NULL DEFAULT '0',
136136
`last_error` text,
137137
PRIMARY KEY (`id`)
138-
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
138+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139139

140140
-- Create syntax for TABLE 'tbStateReportLog'
141141
CREATE TABLE `tbStateReportLog` (
@@ -150,7 +150,7 @@ CREATE TABLE `tbStateReportLog` (
150150
`report_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
151151
`extra_data` text NOT NULL,
152152
PRIMARY KEY (`id`)
153-
) ENGINE=InnoDB AUTO_INCREMENT=4122793 DEFAULT CHARSET=utf8;
153+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
154154

155155
-- Create syntax for TABLE 'tbTask'
156156
CREATE TABLE `tbTask` (

web/aflow/controllers/Flow.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,13 @@ public function show_flow($id) {
302302
}
303303
$this->data["menu"] = 1;
304304
$query_result = $this->flow_manager->find_flow_by_id($id);
305-
$products = $this->flow_manager->get_products();
306-
$flow = $query_result[0];
305+
$products = $this->flow_manager->get_products();
307306

308307
if (count($query_result) == 0) {
309308
show_404();
310309
return;
311310
}
311+
$flow = $query_result[0];
312312
$type = 0;
313313

314314
$flow->tasks = $this->flow_manager->find_tasks_by_flow($id);
@@ -319,6 +319,7 @@ public function show_flow($id) {
319319

320320
public function api() {
321321
if ($this->input->server('REQUEST_METHOD')!="POST") {
322+
var_dump($this->input->server('REQUEST_METHOD'));
322323
return;
323324
}
324325
if (!$this->check_auth('group_user')) {
@@ -346,6 +347,7 @@ public function api() {
346347
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
347348
$headers = substr($response, 0, $header_size);
348349
$body = substr($response, $header_size);
350+
349351
if(curl_errno($ch)) {
350352
show_error(curl_error($ch));
351353
} else {
@@ -393,12 +395,14 @@ public function terminal()
393395
{
394396
function getallheaders()
395397
{
396-
$headers = '';
398+
$headers = array();
397399
foreach ($_SERVER as $name => $value)
398400
{
401+
$iname = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
402+
// var_dump($iname);
399403
if (substr($name, 0, 5) == 'HTTP_')
400404
{
401-
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
405+
$headers[$iname] = $value;
402406
}
403407
}
404408
return $headers;

0 commit comments

Comments
 (0)