Beispiel #1
0
 def run(self):
     logger.info('任务开始: {}'.format(local_now_display()))
     time_start = time.time()
     try:
         self._run()
     except Exception as e:
         logger.error('任务运行出现异常')
         logger.error('下面显示异常 Traceback 信息: ')
         logger.error(e, exc_info=True)
     finally:
         logger.info('\n任务结束: {}'.format(local_now_display()))
         timedelta = round((time.time() - time_start), 2)
         logger.info('用时: {}'.format(timedelta))
Beispiel #2
0
    def get_html_msg(self) -> dict:
        command = self.command
        assets_with_url = []
        for asset in command['assets']:
            url = reverse('assets:asset-detail',
                          kwargs={'pk': asset.id},
                          api_to_ui=True,
                          external=True) + '?oid={}'.format(asset.org_id)
            assets_with_url.append([asset, url])

        level = Command.get_risk_level_str(command['risk_level'])
        items = {
            _("User"): command['user'],
            _("Level"): level,
            _("Date"): local_now_display(),
        }

        context = {
            'items': items,
            'assets_with_url': assets_with_url,
            'command': command['input'],
        }
        message = render_to_string('terminal/_msg_command_execute_alert.html',
                                   context)
        return {'subject': self.subject, 'message': message}
Beispiel #3
0
    def post_run(self):
        self.time_end = time.time()
        self.date_end = timezone.now()

        logger.info('\n\n' + '-' * 80)
        logger.info('计划执行结束 {}\n'.format(local_now_display()))
        self.timedelta = self.time_end - self.time_start
        logger.info('用时: {}s'.format(self.timedelta))
        self.execution.timedelta = self.timedelta
        self.execution.save()
Beispiel #4
0
 def construct_confirm_ticket_meta(request=None):
     login_ip = get_request_ip(request) if request else ''
     login_ip = login_ip or '0.0.0.0'
     login_city = get_ip_city(login_ip)
     login_datetime = local_now_display()
     ticket_meta = {
         'apply_login_ip': login_ip,
         'apply_login_city': login_city,
         'apply_login_datetime': login_datetime,
     }
     return ticket_meta
Beispiel #5
0
 def get_html_msg(self) -> dict:
     now = local_now_display()
     subject = self.oauth_name + ' ' + _('binding reminder')
     context = dict(subject=subject,
                    name=self.user.name,
                    username=self.user.username,
                    ip=self.ip,
                    time=now,
                    oauth_name=self.oauth_name,
                    oauth_id=self.oauth_id)
     message = render_to_string('authentication/_msg_oauth_bind.html',
                                context)
     return {'subject': subject, 'message': message}
Beispiel #6
0
 def get_html_msg(self) -> dict:
     now = local_now_display()
     subject = _('Different city login reminder')
     context = dict(
         subject=subject,
         name=self.user.name,
         username=self.user.username,
         ip=self.ip,
         time=now,
         city=self.city,
     )
     message = render_to_string('authentication/_msg_different_city.html',
                                context)
     return {'subject': subject, 'message': message}
Beispiel #7
0
 def get_html_msg(self) -> dict:
     command = self.command
     session_detail_url = reverse('api-terminal:session-detail',
                                  kwargs={'pk': command['session']},
                                  external=True,
                                  api_to_ui=True) + '?oid={}'.format(
                                      self.command['org_id'])
     session_detail_url = session_detail_url.replace(
         '/terminal/sessions/', '/audit/sessions/sessions/')
     level = Command.get_risk_level_str(command['risk_level'])
     items = {
         _("Asset"): command['asset'],
         _("User"): command['user'],
         _("Level"): level,
         _("Date"): local_now_display(),
     }
     context = {
         'items': items,
         'session_url': session_detail_url,
         "command": command['input'],
     }
     message = render_to_string('terminal/_msg_command_alert.html', context)
     return {'subject': self.subject, 'message': message}