Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
4051225e
Commit
4051225e
authored
Feb 13, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复命令执行bug,修复修改日志级别后无法查看日志
parent
d3bdbc0b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
9 deletions
+35
-9
api.py
apps/common/api.py
+16
-1
celery.py
apps/ops/api/celery.py
+8
-0
command.py
apps/ops/api/command.py
+3
-3
tasks.py
apps/ops/tasks.py
+4
-1
command_execution_create.html
apps/ops/templates/ops/command_execution_create.html
+2
-2
jms
jms
+1
-1
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
apps/common/api.py
View file @
4051225e
...
@@ -206,6 +206,14 @@ class LogTailApi(generics.RetrieveAPIView):
...
@@ -206,6 +206,14 @@ class LogTailApi(generics.RetrieveAPIView):
def
get_log_path
(
self
):
def
get_log_path
(
self
):
raise
NotImplementedError
()
raise
NotImplementedError
()
def
filter_line
(
self
,
line
):
"""
过滤行,可能替换一些信息
:param line:
:return:
"""
return
line
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
mark
=
request
.
query_params
.
get
(
"mark"
)
or
str
(
uuid
.
uuid4
())
mark
=
request
.
query_params
.
get
(
"mark"
)
or
str
(
uuid
.
uuid4
())
log_path
=
self
.
get_log_path
()
log_path
=
self
.
get_log_path
()
...
@@ -224,9 +232,16 @@ class LogTailApi(generics.RetrieveAPIView):
...
@@ -224,9 +232,16 @@ class LogTailApi(generics.RetrieveAPIView):
offset
=
cache
.
get
(
mark
,
0
)
offset
=
cache
.
get
(
mark
,
0
)
f
.
seek
(
offset
)
f
.
seek
(
offset
)
data
=
f
.
read
(
self
.
buff_size
)
.
replace
(
'
\n
'
,
'
\r\n
'
)
data
=
f
.
read
(
self
.
buff_size
)
.
replace
(
'
\n
'
,
'
\r\n
'
)
mark
=
str
(
uuid
.
uuid4
())
mark
=
str
(
uuid
.
uuid4
())
cache
.
set
(
mark
,
f
.
tell
(),
5
)
cache
.
set
(
mark
,
f
.
tell
(),
5
)
if
data
==
''
and
self
.
is_file_finish_write
():
if
data
==
''
and
self
.
is_file_finish_write
():
self
.
end
=
True
self
.
end
=
True
return
Response
({
"data"
:
data
,
'end'
:
self
.
end
,
'mark'
:
mark
})
_data
=
''
for
line
in
data
.
split
(
'
\r\n
'
):
new_line
=
self
.
filter_line
(
line
)
if
line
==
''
:
continue
_data
+=
new_line
+
'
\r\n
'
return
Response
({
"data"
:
_data
,
'end'
:
self
.
end
,
'mark'
:
mark
})
apps/ops/api/celery.py
View file @
4051225e
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#
#
import
os
import
os
import
re
from
celery.result
import
AsyncResult
from
celery.result
import
AsyncResult
from
rest_framework
import
generics
from
rest_framework
import
generics
...
@@ -19,12 +21,18 @@ class CeleryTaskLogApi(LogTailApi):
...
@@ -19,12 +21,18 @@ class CeleryTaskLogApi(LogTailApi):
permission_classes
=
(
IsValidUser
,)
permission_classes
=
(
IsValidUser
,)
task
=
None
task
=
None
task_id
=
''
task_id
=
''
pattern
=
re
.
compile
(
r'Task .* succeeded in \d+\.\d+s.*'
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
task_id
=
str
(
kwargs
.
get
(
'pk'
))
self
.
task_id
=
str
(
kwargs
.
get
(
'pk'
))
self
.
task
=
AsyncResult
(
self
.
task_id
)
self
.
task
=
AsyncResult
(
self
.
task_id
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
def
filter_line
(
self
,
line
):
if
self
.
pattern
.
match
(
line
):
line
=
self
.
pattern
.
sub
(
line
,
''
)
return
line
def
get_log_path
(
self
):
def
get_log_path
(
self
):
new_path
=
get_celery_task_log_path
(
self
.
task_id
)
new_path
=
get_celery_task_log_path
(
self
.
task_id
)
if
new_path
and
os
.
path
.
isfile
(
new_path
):
if
new_path
and
os
.
path
.
isfile
(
new_path
):
...
...
apps/ops/api/command.py
View file @
4051225e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
rest_framework
import
viewsets
from
rest_framework
import
viewsets
from
django.db
import
transaction
from
common.permissions
import
IsValidUser
from
common.permissions
import
IsValidUser
from
..models
import
CommandExecution
from
..models
import
CommandExecution
...
@@ -11,7 +12,6 @@ from ..tasks import run_command_execution
...
@@ -11,7 +12,6 @@ from ..tasks import run_command_execution
class
CommandExecutionViewSet
(
viewsets
.
ModelViewSet
):
class
CommandExecutionViewSet
(
viewsets
.
ModelViewSet
):
serializer_class
=
CommandExecutionSerializer
serializer_class
=
CommandExecutionSerializer
permission_classes
=
(
IsValidUser
,)
permission_classes
=
(
IsValidUser
,)
task
=
None
def
get_queryset
(
self
):
def
get_queryset
(
self
):
return
CommandExecution
.
objects
.
filter
(
return
CommandExecution
.
objects
.
filter
(
...
@@ -22,6 +22,6 @@ class CommandExecutionViewSet(viewsets.ModelViewSet):
...
@@ -22,6 +22,6 @@ class CommandExecutionViewSet(viewsets.ModelViewSet):
instance
=
serializer
.
save
()
instance
=
serializer
.
save
()
instance
.
user
=
self
.
request
.
user
instance
.
user
=
self
.
request
.
user
instance
.
save
()
instance
.
save
()
run_command_execution
.
apply_async
(
transaction
.
on_commit
(
lambda
:
run_command_execution
.
apply_async
(
args
=
(
instance
.
id
,),
task_id
=
str
(
instance
.
id
)
args
=
(
instance
.
id
,),
task_id
=
str
(
instance
.
id
)
)
)
)
apps/ops/tasks.py
View file @
4051225e
...
@@ -41,7 +41,10 @@ def run_ansible_task(tid, callback=None, **kwargs):
...
@@ -41,7 +41,10 @@ def run_ansible_task(tid, callback=None, **kwargs):
@shared_task
@shared_task
def
run_command_execution
(
cid
,
**
kwargs
):
def
run_command_execution
(
cid
,
**
kwargs
):
execution
=
get_object_or_none
(
CommandExecution
,
id
=
cid
)
execution
=
get_object_or_none
(
CommandExecution
,
id
=
cid
)
return
execution
.
run
()
if
execution
:
execution
.
run
()
else
:
logger
.
error
(
"Not found the execution id: {}"
.
format
(
cid
))
@shared_task
@shared_task
...
...
apps/ops/templates/ops/command_execution_create.html
View file @
4051225e
...
@@ -170,8 +170,8 @@ function initResultTerminal() {
...
@@ -170,8 +170,8 @@ function initResultTerminal() {
term
=
new
Terminal
({
term
=
new
Terminal
({
cursorBlink
:
false
,
cursorBlink
:
false
,
screenKeys
:
false
,
screenKeys
:
false
,
fontFamily
:
'"
Monaco", "
Consolas", "monospace"'
,
fontFamily
:
'"Consolas", "monospace"'
,
fontSize
:
1
3
,
fontSize
:
1
4
,
rightClickSelectsWord
:
true
,
rightClickSelectsWord
:
true
,
disableStdin
:
true
,
disableStdin
:
true
,
theme
:
{
theme
:
{
...
...
jms
View file @
4051225e
...
@@ -176,7 +176,7 @@ def start_celery():
...
@@ -176,7 +176,7 @@ def start_celery():
cmd
=
[
cmd
=
[
'celery'
,
'worker'
,
'celery'
,
'worker'
,
'-A'
,
'ops'
,
'-A'
,
'ops'
,
'-l'
,
LOG_LEVEL
.
lower
()
,
'-l'
,
'INFO'
,
'--pidfile'
,
pid_file
,
'--pidfile'
,
pid_file
,
'--autoscale'
,
'20,4'
,
'--autoscale'
,
'20,4'
,
]
]
...
...
requirements/requirements.txt
View file @
4051225e
...
@@ -14,7 +14,7 @@ coreapi==2.3.3
...
@@ -14,7 +14,7 @@ coreapi==2.3.3
coreschema==0.0.4
coreschema==0.0.4
cryptography==2.3.1
cryptography==2.3.1
decorator==4.1.2
decorator==4.1.2
Django==2.1
Django==2.1
.7
django-auth-ldap==1.7.0
django-auth-ldap==1.7.0
django-bootstrap3==9.1.0
django-bootstrap3==9.1.0
django-celery-beat==1.1.1
django-celery-beat==1.1.1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment