Beispiel #1
0
 def remove_job(self, job_id):
     # OtxAdapterのjobsからjob削除
     otx = OtxAdapter.get()
     otx.remove_job(job_id)
     # スケジューラからjob削除
     schedule_job = ScheduleJobs.objects.get(id=job_id)
     self._schedule.remove_job(schedule_job)
     # mongoのschedule_jobsからschedule_job削除
     schedule_job.remove()
Beispiel #2
0
def get_otx_dict(replace_dict):
    replace_dict['otx'] = OtxAdapter.get()
    # communityが削除されている場合はNoneを格納する
    try:
        if replace_dict['otx'].community is None:
            replace_dict['otx'].community = None
    except DoesNotExist:
        replace_dict['otx'].community = None
    return replace_dict
Beispiel #3
0
 def resume_job(self, job_id):
     schedule_job = ScheduleJobs.objects.get(id=job_id)
     if schedule_job in OtxAdapter.get().jobs:
         if schedule_job.status == ScheduleJobs.STATUS_STOP:
             pass
         else:
             print('already working.')
             return
     else:
         raise Exception('invalid job_id')
     self._schedule.resume_job(schedule_job)
Beispiel #4
0
    def pause_job(self, job_id):
        schedule_job = ScheduleJobs.objects.get(id=job_id)
        if schedule_job in OtxAdapter.get().jobs:
            if schedule_job.status == ScheduleJobs.STATUS_IN_OPERATION:
                pass
            else:
                print('not yet start.')
                return
        else:
            raise Exception('invalid job_id')

            return
        self._schedule.pause_job(schedule_job)
Beispiel #5
0
def otx_common_render(request, info_msg=None, error_msg=None):
    try:
        replace_dict = get_common_replace_dict(request)
        # mongoからotx情報を取得
        oa = OtxAdapter.get()
        replace_dict['otx'] = oa
        if info_msg is not None:
            replace_dict['interval_info_msg'] = info_msg
        if error_msg is not None:
            replace_dict['interval_error_msg'] = error_msg
        # レンダリング
        return render(request, 'otx_detail.html', replace_dict)
    except Exception:
        # エラーページ
        return error_page(request)
Beispiel #6
0
    def get_otx_stix(self, mtimestamp=None):
        # OTXアダプタの設定を取得
        otx_conf = OtxAdapter.get()
        key = otx_conf.apikey
        # 登録情報を取得
        community = otx_conf.community
        uploader = otx_conf.uploader
        via = Vias.get_via_adapter_otx(uploader)

        # otxから取得
        try:
            proxies = System.get_request_proxies()
            otx = OTXv2(key, proxies)
            slices = otx.getsince(mtimestamp)
        except Exception as e:
            traceback.print_exc()
            raise e

        # last_requested更新
        otx_conf.modify_last_requested()

        count = 0
        # ひとつずつ取得する
        for slice_ in slices:
            try:
                # stix一つごとに登録処理
                stix = StixExport(slice_)
                stix.build()
                content = stix.to_xml()
                # 取得したSTIXを登録
                _regist_stix(content, community, via)
                count += 1
            except Exception as e:
                # エラーが発生した場合はログを表示して処理は実行する
                traceback.print_exc()
        # 件数を返却
        return count