Esempio n. 1
0
def download(request, response_id, execution_order):
    """
    [メソッド概要]
      アクションログダウンロード処理
    """
    logger.logic_log('LOSI00001',
                     'response_id: %s, execution_order: %s' %
                     (response_id, execution_order),
                     request=request)

    try:
        err_flag = False
        log_message = ''
        log_txt = ''
        lang = request.user.get_lang_mode()

        # ルール別アクセス権限チェック
        act_history_info = ActionHistory.objects.get(
            response_id=response_id, execution_order=execution_order)
        user_auth = request.user_config.get_menu_auth_type(
            MENU_ID, rule_type_id=act_history_info.rule_type_id)
        if user_auth not in defs.MENU_CATEGORY.ALLOW_EVERY:
            logger.user_log('LOSI13003', request.path, user_auth,
                            defs.MENU_CATEGORY.ALLOW_EVERY)
            if 'HTTP_X_REQUESTED_WITH' in request.META and request.META[
                    'HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest':
                return HttpResponse(status=400)
            else:
                return HttpResponseRedirect(
                    reverse('web_app:top:notpermitted'))

        # ログデータ取得
        err_flag, req_dic, act_dic, action_history_log_list = get_logdata(
            request,
            response_id,
            execution_order,
            act_history_info=act_history_info)

        if err_flag:
            logger.system_log(
                'LOSM08001',
                'req_dic: %s, act_dic: %s, action_history_log_list: %s' %
                (req_dic, act_dic, len(action_history_log_list)),
                request=request)
            return HttpResponse(request, status=500)

        # リクエスト情報整形
        log_message += '[' + get_message('MOSJA13001', lang, showMsgId=False) + ']' + '\n' \
                    + get_message('MOSJA13002', lang, showMsgId=False) + ':' + req_dic['req_time_stamp'] + '\n'  \
                    + get_message('MOSJA13003', lang, showMsgId=False) + ':' + req_dic['req_trace_id'] + '\n' \
                    + get_message('MOSJA13004', lang, showMsgId=False) + ':' + req_dic['event_info'] + '\n' \
                    + '\n'

        # アクション情報整形
        log_message += '[' + get_message('MOSJA13005', lang, showMsgId=False) + ']' + '\n' \
                    + get_message('MOSJA13006', lang, showMsgId=False) + ':' + act_dic['act_time_stamp'] + '\n'  \
                    + get_message('MOSJA13003', lang, showMsgId=False) + ':' + act_dic['act_trace_id'] + '\n'  \
                    + get_message('MOSJA13007', lang, showMsgId=False) + ':' + act_dic['rule_type_name'] + '\n'  \
                    + get_message('MOSJA13008', lang, showMsgId=False) + ':' + act_dic['rule_name'] + '\n'  \
                    + get_message('MOSJA13010', lang, showMsgId=False) + ':' + act_dic['action_parameter_info'] + '\n'  \

        # 各ドライバーのアクションの詳細を取得
        func = _get_get_history_data_func(act_history_info.action_type_id)
        history_data = func(act_history_info.pk)

        # ドライバー固有のアクション情報追記
        for k, v in history_data.items():
            if not v:
                v = ''
            log_message += get_message(k, lang,
                                       showMsgId=False) + ':' + str(v) + '\n'

        else:
            log_message += '\n'

        # action_history_listをループしながらテキストにいれる。
        if len(action_history_log_list) > 0:
            log_message += '[' + get_message(
                'MOSJA13011', lang, showMsgId=False) + ']' + '\n'

        for action_log in action_history_log_list:
            msg_params = action_log.message_params
            if not msg_params:
                message = get_message(action_log.message_id,
                                      request.user.get_lang_mode())
            else:
                msg_params = ast.literal_eval(msg_params)
                message = get_message(action_log.message_id,
                                      request.user.get_lang_mode(),
                                      **(msg_params))

            time_stamp = TimeConversion.get_time_conversion(
                action_log.last_update_timestamp,
                'Asia/Tokyo',
                request=request)
            log_message += '[%s] %s\n' % (time_stamp, message)

        # ダウンロード
        rule_name = act_dic['rule_type_name']
        act_type = act_dic['action_type_id']
        act_list = ActionType.objects.all()
        num = act_type - 1
        act_typ = str(act_list[num])
        action_type = act_typ.split('(')[0]
        act_time = act_dic['act_time_stamp']
        action_time = (act_time.translate(
            str.maketrans({
                '-': '',
                '_': '',
                ':': '',
                ' ': ''
            })))
        file_name = 'Action_log_%s_%s_%s.txt' % (rule_name, action_type,
                                                 action_time)

        response = HttpResponse(log_message, content_type='text/plain')
        response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % (
            urllib.parse.quote(file_name))

        logger.logic_log('LOSI00002', 'success', request=request)
        return response

    except Exception as e:
        logger.logic_log(
            'LOSI00005',
            'response_id: %s, execution_order: %s, trace: %s' %
            (response_id, execution_order, traceback.format_exc()),
            request=request)
        return HttpResponse(request, status=500)
Esempio n. 2
0
def get_logdata(request, response_id, execution_order, act_history_info=None):
    """
    [メソッド概要]
      ログデータ取得処理
    [戻り値]
    err_flag: エラーフラグ
    req_dic: リクエスト情報
    act_dic: アクション情報
    action_history_log_list: アクションログ履歴
    """

    logger.logic_log('LOSI00001',
                     'response_id: %s, execution_order: %s' %
                     (response_id, execution_order),
                     request=request)

    try:
        err_flag = True
        req_dic = {}
        act_dic = {}
        action_history_log_list = []

        # requestからレスポンスIDとアクション実行順判定
        if not response_id or not execution_order:
            # 上記がNoneならエラー
            logger.system_log('LOSM08002',
                              response_id,
                              execution_order,
                              request=request)
            return err_flag, req_dic, act_dic, action_history_log_list

        # アクション情報取得
        act_info = RhdmResponseAction.objects.get(
            response_id=response_id, execution_order=execution_order)
        if act_history_info is None:
            act_history_info = ActionHistory.objects.get(
                response_id=response_id, execution_order=execution_order)

        # リクエスト情報取得
        req_info = EventsRequest.objects.get(
            trace_id=act_history_info.trace_id)

        # 日時の整形
        act_time_stamp = TimeConversion.get_time_conversion(
            act_history_info.action_start_time, 'Asia/Tokyo', request=request)
        req_time_stamp = TimeConversion.get_time_conversion(
            req_info.event_to_time, 'Asia/Tokyo', request=request)

        # リクエスト情報取得
        req_dic['req_time_stamp'] = req_time_stamp
        req_dic['req_trace_id'] = req_info.trace_id
        req_dic['event_info'] = req_info.event_info

        # アクション情報取得
        act_dic['act_time_stamp'] = act_time_stamp
        act_dic['act_trace_id'] = act_history_info.trace_id
        act_dic['rule_type_name'] = act_history_info.rule_type_name
        act_dic['action_type_id'] = act_history_info.action_type_id
        act_dic['rule_name'] = act_info.rule_name
        act_dic['action_parameter_info'] = act_info.action_parameter_info

        # アクションログ取得
        action_history_log_list = list(
            ActionLog.objects.filter(
                response_id=response_id,
                execution_order=execution_order).order_by('action_log_id'))

        err_flag = False
        logger.logic_log(
            'LOSI00002',
            'req_dic: %s, act_dic: %s, action_history_log_list: %s' %
            (req_dic, act_dic, len(action_history_log_list)),
            request=request)
        return err_flag, req_dic, act_dic, action_history_log_list

    except Exception as e:
        logger.logic_log(
            'LOSI00005',
            'response_id: %s, execution_order: %s, trace: %s' %
            (response_id, execution_order, traceback.format_exc()),
            request=request)
        return err_flag, req_dic, act_dic, action_history_log_list
Esempio n. 3
0
def dataobject(request, response_id, execution_order):
    """
    [メソッド概要]
    アクション履歴画面の一覧表示
    """
    msg = ''
    req_shape_dic = {}
    act_shape_dic = {}
    log_message = []
    logger.logic_log('LOSI00001',
                     'response_id: %s, execution_order: %s' %
                     (response_id, execution_order),
                     request=request)
    lang = request.user.get_lang_mode()

    try:
        # ルール別アクセス権限チェック
        act_history_info = ActionHistory.objects.get(
            response_id=response_id, execution_order=execution_order)
        user_auth = request.user_config.get_menu_auth_type(
            MENU_ID, rule_type_id=act_history_info.rule_type_id)
        if user_auth not in defs.MENU_CATEGORY.ALLOW_EVERY:
            logger.user_log('LOSI13003', request.path, user_auth,
                            defs.MENU_CATEGORY.ALLOW_EVERY)
            if 'HTTP_X_REQUESTED_WITH' in request.META and request.META[
                    'HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest':
                return HttpResponse(status=400)
            else:
                return HttpResponseRedirect(
                    reverse('web_app:top:notpermitted'))

        # ログデータ取得
        err_flag, req_dic, act_dic, action_history_log_list = get_logdata(
            request,
            response_id,
            execution_order,
            act_history_info=act_history_info)
        if err_flag:
            logger.system_log(
                'LOSM08001',
                'req_dic: %s, act_dic: %s, action_history_log_list: %s' %
                (req_dic, act_dic, len(action_history_log_list)),
                request=request)
            msg = get_message('MOSJA13000', lang)
            raise Exception()

        #[リクエスト情報]
        req_shape_dic[get_message('MOSJA13002', lang,
                                  showMsgId=False)] = req_dic['req_time_stamp']
        req_shape_dic[get_message('MOSJA13003', lang,
                                  showMsgId=False)] = req_dic['req_trace_id']
        req_shape_dic[get_message('MOSJA13004', lang,
                                  showMsgId=False)] = req_dic['event_info']

        #[アクション情報]
        act_shape_dic[get_message('MOSJA13006', lang,
                                  showMsgId=False)] = act_dic['act_time_stamp']
        act_shape_dic[get_message('MOSJA13003', lang,
                                  showMsgId=False)] = act_dic['act_trace_id']
        act_shape_dic[get_message('MOSJA13007', lang,
                                  showMsgId=False)] = act_dic['rule_type_name']
        act_shape_dic[get_message('MOSJA13008', lang,
                                  showMsgId=False)] = act_dic['rule_name']
        act_shape_dic[get_message(
            'MOSJA13010', lang,
            showMsgId=False)] = act_dic['action_parameter_info']

        # 各ドライバーのアクションの詳細を取得
        func = _get_get_history_data_func(act_history_info.action_type_id)
        history_data = func(act_history_info.pk)

        # ドライバー固有のアクション情報
        for k, v in history_data.items():
            act_shape_dic[get_message(k, lang, showMsgId=False)] = v

        #[ログ]
        for log in action_history_log_list:
            msg_params = log.message_params
            if not msg_params:
                message = get_message(log.message_id, lang)

            else:
                msg_params = ast.literal_eval(msg_params)
                message = get_message(log.message_id, lang, **(msg_params))

            time_stamp = TimeConversion.get_time_conversion(
                log.last_update_timestamp, 'Asia/Tokyo', request=request)
            message = '[' + time_stamp + ']' + message
            log_message.append(message)

        data = {
            'message': msg,
            'mainmenu_list': request.user_config.get_menu_list(),
            'action_info_dict': act_shape_dic,
            'request_info_dict': req_shape_dic,
            'action_log_list': log_message,
            'user_name': request.user.user_name,
            'lang_mode': request.user.get_lang_mode(),
        }

        logger.logic_log('LOSI00002', 'success', request=request)
        return render(request, 'rule/action_history_data.html', data)

    except Exception as e:
        logger.logic_log(
            'LOSI00005',
            'response_id: %s, execution_order: %s, trace: %s' %
            (response_id, execution_order, traceback.format_exc()),
            request=request)
        if not msg:
            msg = get_message('MOSJA13000', lang)

        data = {
            'message': msg,
            'mainmenu_list': request.user_config.get_menu_list(),
            'action_info_dict': '',
            'request_info_dict': '',
            'action_log_list': '',
            'user_name': request.user.user_name,
            'lang_mode': request.user.get_lang_mode(),
        }

        response_json = json.dumps(data)
        return HttpResponse(response_json, content_type="application/json")