mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 16:39:28 +00:00
[Feature] 作业中心/任务列表/任务详情 最后运行成功或失败的主机 (#4090)
This commit is contained in:
@@ -118,6 +118,24 @@ class Task(PeriodTaskModelMixin, OrgModelMixin):
|
||||
kwargs = {"callback": self.callback}
|
||||
return name, task, args, kwargs
|
||||
|
||||
@lazyproperty
|
||||
def last_success(self):
|
||||
return self._last_adhocexecution(True, 'contacted')
|
||||
|
||||
@lazyproperty
|
||||
def last_failure(self):
|
||||
return self._last_adhocexecution(False, 'dark')
|
||||
|
||||
def _last_adhocexecution(self, is_success, key):
|
||||
obj = AdHocExecution.objects.filter(task_id=self.id, is_success=is_success).order_by('-date_finished').first()
|
||||
body = obj.summary.get(key)
|
||||
if body:
|
||||
asset, body = body.popitem()
|
||||
action, body = body.popitem()
|
||||
return asset, action, body.get('msg', '')
|
||||
else:
|
||||
return '', '', ''
|
||||
|
||||
def __str__(self):
|
||||
return self.name + '@' + str(self.org_id)
|
||||
|
||||
|
Reference in New Issue
Block a user