Exemplo n.º 1
0
def get_qry_status(options, headers, data):
    log.debug("Calling get_qry_status()")
    result = requests.post(options["esm_url"] + '/rs/esm/v2/qryGetStatus',
                           headers=headers,
                           data=data,
                           verify=options["trust_cert"])
    check_status_code(result.status_code)

    return result.json()
Exemplo n.º 2
0
def get_results(options, session_header, qconf_json):
    log.debug("Calling get_results() with {}".format(qconf_json))
    result = requests.post(
        options["esm_url"] +
        '/rs/esm/v2/qryGetResults?startPos=0&numRows=100&reverse=false',
        headers=session_header,
        data=qconf_json,
        verify=options["trust_cert"])
    check_status_code(result.status_code)

    return result.json()
Exemplo n.º 3
0
def alarm_get_triggered_alarms(rc, options, params):
    url = options["esm_url"] + "/rs/esm/v2/alarmGetTriggeredAlarms"

    headers = get_authenticated_headers(rc, options["esm_url"], options["esm_username"],
                                        options["esm_password"], options["trust_cert"])

    r = rc.execute_call_v2('post', url, headers=headers, params=params, verify=options["trust_cert"],
                           proxies=rc.get_proxies())
    check_status_code(r.status_code)

    return r.json()
def case_get_case_list(options):
    url = options["esm_url"] + "/rs/esm/v2/caseGetCaseList"

    headers = get_authenticated_headers(options["esm_url"],
                                        options["esm_username"],
                                        options["esm_password"],
                                        options["trust_cert"])

    r = requests.post(url, headers=headers, verify=options["trust_cert"])
    check_status_code(r.status_code)

    return r.json()
Exemplo n.º 5
0
def get_qry_status(rc, options, headers, data):
    log.debug("Calling get_qry_status()")
    url = options["esm_url"] + '/rs/esm/v2/qryGetStatus'

    result = rc.execute_call_v2('post',
                                url,
                                headers=headers,
                                data=data,
                                verify=options["trust_cert"],
                                proxies=rc.get_proxies())
    check_status_code(result.status_code)

    return result.json()
Exemplo n.º 6
0
def get_results(rc, options, session_header, qconf_json):
    log.debug("Calling get_results() with {}".format(qconf_json))
    url = options[
        "esm_url"] + '/rs/esm/v2/qryGetResults?startPos=0&numRows=100&reverse=false'

    result = rc.execute_call_v2('post',
                                url,
                                headers=session_header,
                                data=qconf_json,
                                verify=options["trust_cert"],
                                proxies=rc.get_proxies())
    check_status_code(result.status_code)

    return result.json()
def case_get_case_detail(options, headers, id):
    url = options["esm_url"] + "/rs/esm/v2/caseGetCaseDetail"

    payload = {"id": id}

    r = requests.post(url,
                      headers=headers,
                      data=json.dumps(payload),
                      verify=options["trust_cert"])
    log.debug(r.content)
    if r.status_code == 400:
        raise FunctionError(r.content)
    check_status_code(r.status_code)

    return r.json()
def alarm_get_triggered_alarms(options, params):
    url = options["esm_url"] + "/rs/esm/v2/alarmGetTriggeredAlarms"

    headers = get_authenticated_headers(options["esm_url"],
                                        options["esm_username"],
                                        options["esm_password"],
                                        options["trust_cert"])

    r = requests.post(url,
                      headers=headers,
                      params=params,
                      verify=options["trust_cert"])
    check_status_code(r.status_code)

    return r.json()
def case_get_case_events_details(options, ids):
    url = options["esm_url"] + "/rs/esm/v2/caseGetCaseEventsDetail"

    headers = get_authenticated_headers(options["esm_url"],
                                        options["esm_username"],
                                        options["esm_password"],
                                        options["trust_cert"])
    payload = {"eventIds": {"list": [ids]}}

    r = requests.post(url,
                      headers=headers,
                      data=json.dumps(payload),
                      verify=options["trust_cert"])
    check_status_code(r.status_code)

    return r.json()
Exemplo n.º 10
0
def case_get_case_list(rc, options):
    url = options["esm_url"] + "/rs/esm/v2/caseGetCaseList"

    headers = get_authenticated_headers(rc, options["esm_url"],
                                        options["esm_username"],
                                        options["esm_password"],
                                        options["trust_cert"])

    r = rc.execute_call_v2('post',
                           url,
                           headers=headers,
                           verify=options["trust_cert"],
                           proxies=rc.get_proxies())
    check_status_code(r.status_code)

    return r.json()
def case_edit_case_details(rc, options, dict_payload, case_id):
    headers = get_authenticated_headers(rc, options["esm_url"], options["esm_username"],
                                       options["esm_password"], options["trust_cert"])

    case_details = case_get_case_detail(rc, options, headers, case_id)
    case_assigned_dict = dict(caseDetail={})
    case_assigned_dict["caseDetail"]["assignedTo"] = case_details.get("assignedTo")
    case_assigned_dict["caseDetail"]["orgId"] = case_details.get("orgId")

    dict_payload["caseDetail"] = merge_two_dicts(case_details, dict_payload["caseDetail"])

    url = options["esm_url"] + "/rs/esm/v2/caseEditCase"

    r = rc.execute_call_v2('post', url,  headers=headers, data=json.dumps(dict_payload), verify=options["trust_cert"],
                           proxies=rc.get_proxies())

    check_status_code(r.status_code)
Exemplo n.º 12
0
def case_get_case_detail(rc, options, headers, id):
    url = options["esm_url"] + "/rs/esm/v2/caseGetCaseDetail"

    payload = {"id": id}

    r = rc.execute_call_v2('post',
                           url,
                           headers=headers,
                           data=json.dumps(payload),
                           verify=options["trust_cert"],
                           proxies=rc.get_proxies())
    log.debug(r.content)
    if r.status_code == 400:
        raise FunctionError(r.content)
    check_status_code(r.status_code)

    return r.json()
Exemplo n.º 13
0
def query_esm(rc, options, headers, data, type):
    log.debug("Calling query_esm()")
    base_url = options["esm_url"]
    url = base_url + "/rs/esm/v2/qryExecuteDetail?type={}&reverse=False".format(
        type)

    r = rc.execute_call_v2('post',
                           url,
                           headers=headers,
                           data=data,
                           verify=options["trust_cert"],
                           proxies=rc.get_proxies())
    check_status_code(r.status_code)

    # return r.json()
    result_dict = r.json()
    queryID = result_dict.get("resultID")

    # Check the query status
    qconf = {"resultID": queryID}
    qconf_json = json.dumps(qconf)

    status_dict = get_qry_status(rc, options, headers, qconf_json)
    status = status_dict.get("percentComplete")

    # If the query is not 100% complete it will wait 10 seconds and then check again. If the query is not complete after
    # 10 mins, an Error is raised indicating something went wrong.
    for i in range(60):
        if status == 100:
            break
        else:
            time.sleep(10)
            status_dict = get_qry_status(rc, options, headers, qconf_json)
            status = status_dict.get("percentComplete")
        if status != 100 and i == 59:
            raise FunctionError("Query timed out.")

    total_records = status_dict.get("totalRecords")
    return qconf_json, total_records
 def test_check_status_invalid(self):
     try:
         check_status_code(404)
         assert False
     except ValueError:
         assert True