コード例 #1
0
def system_cron():
    """spreadsheet export via scheduled task to server file system"""

    # prepare time for output file
    filetime = timezone.now().strftime('%Y%m%d_%H%M')

    # get config
    main_config_model = MainConfigModel.objects.get(main_config_name='MainConfig')

    # check file system
    stop_cron_exporter = check_content_file_system(main_config_model, 'SYSTEM_XLS')

    # leave if config caused errors
    if stop_cron_exporter:
        # return to scheduled task
        return

    # prepare output file path
    output_file_path = (
        main_config_model.cron_export_path + '/' + filetime + '_systems.xls'
    )

    # get username from config
    username = main_config_model.cron_username

    # call main function
    xls_disk = write_xls(username)

    # save spreadsheet to disk
    xls_disk.save(output_file_path)

    # call logger
    info_logger(username, ' SYSTEM_XLS_FILE_WRITTEN ' + output_file_path)
コード例 #2
0
def system_create_cron(request):
    """helper function to check config before creating scheduled task"""

    # get config
    main_config_model = MainConfigModel.objects.get(
        main_config_name='MainConfig')

    # check file system
    stop_cron_exporter = check_content_file_system(main_config_model,
                                                   'SYSTEM_CSV', request)

    # check stop condition
    if stop_cron_exporter:
        # return to 'system_list'
        return redirect(reverse('system_list'))
    else:

        # create parameter dict
        params = {}

        # prepare parameter dict
        params['name'] = 'system_spreadsheet_exporter_csv'
        params['func'] = 'dfirtrack_main.exporter.spreadsheet.csv.system_cron'

        # build url
        urlpath = '/admin/django_q/schedule/add/'
        urlquery = urlencode(params)
        admin_url_create_cron = urlunparse(('', '', urlpath, '', urlquery, ''))

        # open django admin with pre-filled form for scheduled task
        return redirect(admin_url_create_cron)
コード例 #3
0
def artifact_create_cron(request):
    """helper function to check config before creating scheduled task"""

    # get config
    main_config_model = MainConfigModel.objects.get(main_config_name='MainConfig')

    # check file system
    stop_cron_exporter = check_content_file_system(
        main_config_model, 'ARTIFACT_XLS', request
    )

    # check stop condition
    if stop_cron_exporter:
        # return to 'artifact_list'
        return redirect(reverse('artifacts_artifact_list'))
    else:
        # TODO: [logic] build url with python
        # open django admin with pre-filled form for scheduled task
        return redirect(
            '/admin/django_q/schedule/add/?name=artifact_spreadsheet_exporter_xls&func=dfirtrack_artifacts.exporter.spreadsheet.xls.artifact_cron'
        )