IBM QRadar SOAR

IBM QRadar SOAR

Join this online user group to communicate across Security product users and IBM experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  CALL REST API timeout issue when it doesn't return status code

    Posted Thu August 08, 2024 05:55 PM

    I am using the CALL REST API module with the Forescout.  

    When making the API call to Forescout, if the IP finds a match, it returns the result fine. 
    In the case there is no match, the playbook timeout with error.

    https://forescout.mycompay/api/hosts/ip/1.1.1.1'




    I tried the output script below to validate the status code but still getting the timeout issue when there is no match.  what condition can I use to get pass this error.

    import json
    import re
    results = playbook.functions.results.rest_result
    #
    if result.status_code != 200
      incident.addNote("404 Error: Host Not found")
    else:
      incident.addNote(str(results))




    ------------------------------
    Raymond Tam
    ------------------------------


  • 2.  RE: CALL REST API timeout issue when it doesn't return status code

    Posted Thu August 08, 2024 08:33 PM

    Hi Raymond,


    The rest api result should be like:

    [rest_api] Result: {'version': 2.0, 'success': True, 'reason': None, 'content': {'ok': True, 'url': 'https://github.com/', 'status_code': 200, 'reason': 'OK',.........

    So, the output script you can adjust it as follows,

    results = playbook.functions.results.rest_result
    if results.content.status_code != 200:
      incident.addNote("404 Error: Host Not found")
    else:
      incident.addNote(str(results))

    I hope this is of assistance.



    ------------------------------
    Allen Lee
    ------------------------------



  • 3.  RE: CALL REST API timeout issue when it doesn't return status code

    Posted Thu August 08, 2024 09:15 PM

    Thanks for the suggestion.  I just tried that but got the same error.

    I do understand your point.  In most cases, I was able to do a simple output script to show the AP return details either there is a match or not.
    In this situation, if API search is not found, the playbook can't run and simple return an error. 

    I even tried this output script below to get the API result but still getting an error when there is no match.


    results = playbook.functions.results.rest_result
    incident.addNote(f"{results}")



    ------------------------------
    Raymond Tam
    ------------------------------



  • 4.  RE: CALL REST API timeout issue when it doesn't return status code
    Best Answer

    Posted Mon August 12, 2024 11:52 PM

    Hi Raymond,

    Can you try to put the rest_api_allowed_status_codes in 404?

    When I do this, it will succeed in outputting the incident note.



    ------------------------------
    Allen Lee
    ------------------------------



  • 5.  RE: CALL REST API timeout issue when it doesn't return status code

    Posted Tue August 13, 2024 12:00 PM

    Thanks for the suggestion; since I am using the script, I added that in the allowed status in the code but got this error.  Anyone has any ideas if I am doing it right?
    See my REST API CAll script below.

    import json
    results = playbook.functions.results.rest_token
    content = results.content
    token = content.text
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': token
    }
    inputs.rest_api_method = 'GET'
    inputs.rest_api_headers = json.dumps(headers)
    inputs.rest_api_url = 'https://forescout.mycompany.com/api/hosts/ip/{}'.format(artifact.value)
    inputs.rest_api_verify = False
    inputs.rest_api_timeout = 60
    inputs.rest_api_allowed_status_codes = 404



    ------------------------------
    Raymond Tam
    ------------------------------



  • 6.  RE: CALL REST API timeout issue when it doesn't return status code

    Posted Tue August 13, 2024 12:11 PM

    I tried again and figured out I was missing the double quote.   The API call is now working fine even if there is no match.  Thanks a lot for the solution.

    inputs.rest_api_allowed_status_codes = "404,200,400"



    ------------------------------
    Raymond Tam
    ------------------------------