Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
419876b5
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
419876b5
编写于
11月 13, 2016
作者:
baltery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update heatbeat
上级
26352174
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
77 addition
and
82 deletion
+77
-82
apps/celerybeat-schedule.db
apps/celerybeat-schedule.db
+0
-0
apps/celerybeat.pid
apps/celerybeat.pid
+0
-1
apps/common/__init__.py
apps/common/__init__.py
+1
-2
apps/common/celery.py
apps/common/celery.py
+20
-20
apps/common/tasks.py
apps/common/tasks.py
+2
-33
apps/jumpserver/settings.py
apps/jumpserver/settings.py
+14
-0
apps/terminal/api.py
apps/terminal/api.py
+15
-14
apps/terminal/models.py
apps/terminal/models.py
+2
-3
apps/terminal/serializers.py
apps/terminal/serializers.py
+13
-4
apps/terminal/tasks.py
apps/terminal/tasks.py
+5
-0
apps/terminal/urls.py
apps/terminal/urls.py
+4
-4
run_server.py
run_server.py
+1
-1
未找到文件。
apps/celerybeat-schedule.db
已删除
100644 → 0
浏览文件 @
26352174
apps/celerybeat.pid
已删除
100644 → 0
浏览文件 @
26352174
64256
apps/common/__init__.py
浏览文件 @
419876b5
...
...
@@ -2,5 +2,4 @@ from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
# from .celery import app as celery_app
from
.celery
import
app
as
celery_app
apps/common/celery.py
浏览文件 @
419876b5
#
#
~*~ coding: utf-8 ~*~
#
#
from __future__ import absolute_import, unicode_literals
#
import os
#
# from celery import Celery
#
# # set the default Django settings module for the 'celery' program.
#
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings')
#
# from django.conf import settings
#
# app = Celery('jumpserver')
#
# # Using a string here means the worker will not have to
#
# pickle the object when using Windows.
#
app.config_from_object('django.conf:settings')
#
#
app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS])
#
# ~*~ coding: utf-8 ~*~
from
__future__
import
absolute_import
,
unicode_literals
import
os
from
datetime
import
timedelta
from
celery
import
Celery
#
set the default Django settings module for the 'celery' program.
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'jumpserver.settings'
)
from
django.conf
import
settings
app
=
Celery
(
'jumpserver'
)
#
Using a string here means the worker will not have to
#
pickle the object when using Windows.
app
.
config_from_object
(
'django.conf:settings'
)
app
.
autodiscover_tasks
(
lambda
:
[
app_config
.
split
(
'.'
)[
0
]
for
app_config
in
settings
.
INSTALLED_APPS
])
apps/common/tasks.py
浏览文件 @
419876b5
from
__future__
import
absolute_import
import
os
from
celery
import
shared_task
from
celery.schedules
import
crontab
# from celery import shared_task
from
django.core.mail
import
send_mail
# from django.conf import settings
# from common import celery_app
from
celery
import
Celery
# set the default Django settings module for the 'celery' program.
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'jumpserver.settings'
)
from
django.conf
import
settings
app
=
Celery
(
'jumpserver'
)
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app
.
config_from_object
(
'django.conf:settings'
)
app
.
autodiscover_tasks
(
lambda
:
[
app_config
.
split
(
'.'
)[
0
]
for
app_config
in
settings
.
INSTALLED_APPS
])
from
common
import
celery_app
as
app
@
app
.
task
...
...
@@ -44,17 +27,3 @@ def send_mail_async(*args, **kwargs):
args
=
tuple
(
args
)
send_mail
(
*
args
,
**
kwargs
)
# @celery_app.task
# def test(arg):
# print(arg)
# celery_app.conf.beat_schedule = {
# 'add-every-30-seconds': {
# 'task': 'common.test',
# 'schedule': crontab(minute='*/1'),
# 'args': ('nihao',)
# }
# }
apps/jumpserver/settings.py
浏览文件 @
419876b5
...
...
@@ -14,6 +14,7 @@ import os
import
sys
from
django.urls
import
reverse_lazy
from
datetime
import
timedelta
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
...
...
@@ -284,6 +285,19 @@ BROKER_URL = 'redis://%(password)s%(host)s:%(port)s/3' % {
}
CELERY_RESULT_BACKEND
=
BROKER_URL
# TERMINAL_HEATBEAT_INTERVAL = CONFIG.TERMINAL_HEATBEAT_INTERVAL or 30
# crontab job
# CELERYBEAT_SCHEDULE = {
# Check terminal is alive every 10m
# 'check_terminal_alive': {
# 'task': 'terminal.tasks.check_terminal_alive',
# 'schedule': timedelta(seconds=TERMINAL_HEATBEAT_INTERVAL),
# 'args': (),
# },
# }
# Cache use redis
CACHES
=
{
'default'
:
{
...
...
apps/terminal/api.py
浏览文件 @
419876b5
...
...
@@ -4,17 +4,17 @@
from
django.core.cache
import
cache
from
django.conf
import
settings
from
rest_framework.generics
import
ListCreateAPIView
,
RetrieveUpdateDestroyAPIView
from
rest_framework
import
viewsets
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.viewsets
import
ModelViewSet
from
rest_framework.permissions
import
AllowAny
from
common.utils
import
signer
,
get_object_or_none
from
.models
import
Terminal
,
HeatbeatFailedLog
from
.models
import
Terminal
,
TerminalHeatbeat
from
.serializers
import
TerminalSerializer
,
TerminalHeatbeatSerializer
from
.hands
import
IsSuperUserOrTerminalUser
class
TerminalViewSet
(
ModelViewSet
):
class
TerminalViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Terminal
.
objects
.
all
()
serializer_class
=
TerminalSerializer
permission_classes
=
(
AllowAny
,)
...
...
@@ -46,18 +46,19 @@ class TerminalViewSet(ModelViewSet):
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
class
TerminalHeatbeatApi
(
APIView
):
# model = HeatbeatFailedLog
#
serializer_class = TerminalHeatbeatSerializer
class
TerminalHeatbeatApi
(
ListCreate
APIView
):
queryset
=
TerminalHeatbeat
.
objects
.
all
()
serializer_class
=
TerminalHeatbeatSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
def
put
(
self
,
request
,
*
args
,
**
kwargs
):
terminal_id
=
request
.
user
.
id
cache
.
set
(
'terminal_heatbeat_%s'
%
terminal_id
,
settings
.
CONFIG
.
TERMINAL_HEATBEAT_INTERVAL
*
3
)
return
Response
({
'msg'
:
'Success'
})
class
TerminalHeatbeatViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
TerminalHeatbeat
.
objects
.
all
()
serializer_class
=
TerminalHeatbeatSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
terminal
=
request
.
user
TerminalHeatbeat
.
objects
.
create
(
terminal
=
terminal
)
return
Response
({
'msg'
:
'Success'
})
# class TerminalApiDetailUpdateDetailApi(RetrieveUpdateDestroyAPIView):
# queryset = Terminal.objects.all()
# serializer_class = TerminalSerializer
# permission_classes = (IsSuperUserOrTerminalUser,)
apps/terminal/models.py
浏览文件 @
419876b5
...
...
@@ -36,10 +36,9 @@ class Terminal(models.Model):
ordering
=
[
'is_active'
]
class
HeatbeatFailedLog
(
models
.
Model
):
"""Terminal heatbeat failed log"""
class
TerminalHeatbeat
(
models
.
Model
):
terminal
=
models
.
ForeignKey
(
Terminal
,
on_delete
=
models
.
CASCADE
)
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
class
Meta
:
db_table
=
'
heatbeat_failed_log
'
db_table
=
'
terminal_heatbeat
'
apps/terminal/serializers.py
浏览文件 @
419876b5
# -*- coding: utf-8 -*-
#
from
django.utils
import
timezone
from
rest_framework
import
serializers
from
.models
import
Terminal
,
HeatbeatFailedLog
from
.models
import
Terminal
,
TerminalHeatbeat
from
.hands
import
ProxyLog
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
proxy_online
=
serializers
.
SerializerMethodField
()
is_alive
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
Terminal
fields
=
[
'id'
,
'name'
,
'ip'
,
'type'
,
'url'
,
'comment'
,
'is_active'
,
'get_type_display'
,
'proxy_online'
]
'is_active'
,
'get_type_display'
,
'proxy_online'
,
'is_alive'
]
@
staticmethod
def
get_proxy_online
(
obj
):
return
ProxyLog
.
objects
.
filter
(
terminal
=
obj
.
name
,
is_finished
=
False
).
count
()
@
staticmethod
def
get_is_alive
(
obj
):
log
=
obj
.
terminalheatbeat_set
.
last
()
if
timezone
.
now
()
-
log
.
date_created
>
timezone
.
timedelta
(
seconds
=
600
):
return
False
else
:
return
True
class
TerminalHeatbeatSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
HeatbeatFailedLog
fields
=
[
'terminal'
]
model
=
TerminalHeatbeat
if
__name__
==
'__main__'
:
...
...
apps/terminal/tasks.py
0 → 100644
浏览文件 @
419876b5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
apps/terminal/urls.py
浏览文件 @
419876b5
...
...
@@ -16,10 +16,10 @@ urlpatterns = [
]
router
=
routers
.
DefaultRouter
()
router
.
register
(
r
'v1/terminal/heatbeat'
,
api
.
TerminalHeatbeatViewSet
,
'api-terminal-heatbeat'
)
router
.
register
(
r
'v1/terminal'
,
api
.
TerminalViewSet
,
'api-terminal'
)
urlpatterns
+=
[
url
(
r
'^v1/terminal/heatbeat/$'
,
api
.
TerminalHeatbeatApi
.
as_view
(),
name
=
'terminal-heatbeat-api'
),
]
# urlpatterns += [
# url(r'v1/terminal/heatbeat/', api.TerminalHeatbeatApi.as_view(), name='api-terminal-heatbeat')
# ]
urlpatterns
+=
router
.
urls
run_server.py
浏览文件 @
419876b5
...
...
@@ -30,7 +30,7 @@ def start_celery():
os
.
chdir
(
apps_dir
)
os
.
environ
.
setdefault
(
'C_FORCE_ROOT'
,
'1'
)
print
(
'start celery'
)
subprocess
.
call
(
'celery -A common worker -
l info
'
,
shell
=
True
)
subprocess
.
call
(
'celery -A common worker -
B -s /tmp/celerybeat-schedule -l info
'
,
shell
=
True
)
def
main
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录