def create_job(request, *args, **kwargs):    
    status, content = forward_request(request)
    if status_ok(status):
        if request["post"].get("exec_mode", "").lower() == "oneshot":
            return status, xml2json.from_job_results(content, format=xml2json.ResultFormat.ROW)
        else:
            return status, xml2json.from_job_create(content)
    else:
        return status, xml2json.from_messages_only(content)
Beispiel #2
0
def create_job(request, *args, **kwargs):
    status, content = forward_request(request)
    if status_ok(status):
        if request["post"].get("exec_mode", "").lower() == "oneshot":
            return status, xml2json.from_job_results(
                content, format=xml2json.ResultFormat.ROW)
        else:
            return status, xml2json.from_job_create(content)
    else:
        return status, xml2json.from_messages_only(content)
def job_data(request, sid, data_source, *args, **kwargs):
    """Handle requests to /search/jobs/<sid>/<data_source>.
    """
    # This replicates some of the code in unless_error, but it has
    # many more special cases than the other endpoints, and introduces
    # much more complexity into unless_error than is justified by
    # repeating a couple of lines here.
    mode = request["get"].get("output_mode", "")
    request = output_mode('xml')(request)
    status, content = forward_request(request)

    if status_ok(status):
        if data_source == "search.log":
            return status, {"entry": {"content": content}}
        if not content:
            return status, content
            
        root = et.fromstring(content)
        if root.tag in ('events', 'results', 'results_preview'):
            if mode == "json_rows":
                format = xml2json.ResultFormat.ROW
            elif mode == "json_cols":
                format = xml2json.ResultFormat.COLUMN
            elif mode == "json":
                format = xml2json.ResultFormat.VERBOSE
            else:
                format = xml2json.ResultFormat.ROW
            
            return status, xml2json.from_job_results(root, format=format)
        elif root.tag == 'timeline':
            return status, xml2json.from_search_timeline(root)
        elif root.tag == 'summary':
            return status, xml2json.from_search_summary(root)
        else:
            return status, xml2json.from_messages_only(root)
    else:
        return status, xml2json.from_messages_only(content)
Beispiel #4
0
def job_data(request, sid, data_source, *args, **kwargs):
    """Handle requests to /search/jobs/<sid>/<data_source>.
    """
    # This replicates some of the code in unless_error, but it has
    # many more special cases than the other endpoints, and introduces
    # much more complexity into unless_error than is justified by
    # repeating a couple of lines here.
    mode = request["get"].get("output_mode", "")
    request = output_mode('xml')(request)
    status, content = forward_request(request)

    if status_ok(status):
        if data_source == "search.log":
            return status, content
        if not content:
            return status, content
        root = et.fromstring(content)
        if root.tag in ('events', 'results', 'results_preview'):
            if mode == "json_rows":
                format = xml2json.ResultFormat.ROW
            elif mode == "json_cols":
                format = xml2json.ResultFormat.COLUMN
            elif mode == "json":
                format = xml2json.ResultFormat.VERBOSE
            else:
                format = xml2json.ResultFormat.ROW

            return status, xml2json.from_job_results(root, format=format)
        elif root.tag == 'timeline':
            return status, xml2json.from_search_timeline(root)
        elif root.tag == 'summary':
            return status, xml2json.from_search_summary(root)
        else:
            return status, xml2json.from_messages_only(root)
    else:
        return status, xml2json.from_messages_only(content)