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

API call incidents/query returns unexpected results

  • 1.  API call incidents/query returns unexpected results

    Posted 3 hours ago
    Edited by Guido Janssens 3 hours ago

    We use the API to collect date from incidents into a management reporting tool.
    The data returned by the API sometimes does not reflect the correct data in SOAR.
    Some fields (e.g. determined_date) area always returned empty, and in some cases we get incident data spread over two records.

    FYI : used version is 51.0.10.0

    Script for call (essentials only - as it is later parsed into a CSV whith some cleaning up of the fields) 

    # =====================================================================
    # MAIN EXPORT SCRIPT
    # =====================================================================

    def main():

        CUSTOM_CONFIG_PATH = "/mgmt/data/xu6/.resilient/app.config"

        if not os.path.exists(CUSTOM_CONFIG_PATH):
            print(f"Error: Configuration file not found at: {CUSTOM_CONFIG_PATH}")
            return

        parser = resilient.ArgumentParser(config_file=CUSTOM_CONFIG_PATH)
        opts = parser.parse_args()

        try:
            client = resilient.get_client(opts)
        except Exception as e:
            print(f"Authentication failed: {e}")
            return

        # -------------------------------------------------------------
        # Load lookup data from cache, or rebuild it when stale/missing
        # -------------------------------------------------------------

        field_value_maps, identity_fields, identity_map = get_lookup_data(client)

        # -------------------------------------------------------------
        # Query incidents
        # -------------------------------------------------------------

        one_year_ago = datetime.utcnow() - timedelta(days=365)
        one_year_ago_ms = int(time.mktime(one_year_ago.timetuple()) * 1000)

        query_uri = "/incidents/query?return_level=full"

        query_payload = {
            "filters": [
                {
                    "conditions": [
                        {
                            "field_name": "create_date",
                            "method": "gte",
                            "value": one_year_ago_ms
                        }
                    ]
                }
            ]
        }

        print(
            f"Querying incidents created since "
            f"{one_year_ago.strftime('%Y-%m-%d %H:%M:%S')}..."
        )

        try:
            response = client.post(query_uri, query_payload)
        except Exception as e:
            print(f"REST Query Execution Failed: {e}")
            return

        if isinstance(response, dict) and "data" in response:
            incidents = response["data"]
        else:
            incidents = response

        if incidents is None:
            incidents = []

     



    ------------------------------
    Guido Janssens
    CERT - Information Risk Officer
    KBC Group NV
    ------------------------------