diff --git a/util-scripts/acs-correlation-example/Dockerfile b/util-scripts/acs-correlation-example/Dockerfile index 36def15..2ff4d5f 100644 --- a/util-scripts/acs-correlation-example/Dockerfile +++ b/util-scripts/acs-correlation-example/Dockerfile @@ -7,15 +7,16 @@ FROM registry.access.redhat.com/ubi9:9.1.0-1782 #Change User USER 0 + # Install the required software RUN dnf install -y wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel && \ - wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz && \ - tar xzf Python-3.10.8.tgz && \ - cd Python-3.10.8 && \ + wget https://www.python.org/ftp/python/3.13.2/Python-3.13.2.tgz && \ + tar xzf Python-3.13.2.tgz && \ + cd Python-3.13.2 && \ ./configure --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions && \ make altinstall && \ cd .. && \ - rm Python-3.10.8.tgz + rm Python-3.13.2.tgz # # Install pip # RUN curl -O https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && python3 get-pip.py @@ -30,7 +31,7 @@ COPY ./ ./app WORKDIR ./app #Install App Dependecies -RUN pip3.10 install -r requirements.txt && pip3.10 install --upgrade pip +RUN pip3.13 install -r requirements.txt && pip3.13 install --upgrade pip #Expose Ports EXPOSE 8080/tcp @@ -38,8 +39,5 @@ EXPOSE 8080/tcp #Change Permissions to allow not root-user work RUN chmod -R g+rw ./ -#Change User -USER 1001 - #ENTRY -ENTRYPOINT python3.10 app.py +ENTRYPOINT python3.13 app.py diff --git a/util-scripts/acs-correlation-example/README.md b/util-scripts/acs-correlation-example/README.md index 30dbf81..28c285f 100644 --- a/util-scripts/acs-correlation-example/README.md +++ b/util-scripts/acs-correlation-example/README.md @@ -17,7 +17,30 @@ podman build -t quick_acs_app . ``` + - Copy and update endpoint list file and token + ```bash + export CENTRAL_API_URL="https://console-openshift-console.apps.cluster1.sandbox568.opentlc.com" + export MAIN_ACS_TOKEN="" + export ENDPOINT_DIR=$(mktemp -d -t ACS_Endpoint_List_XXXX ) + export OUTPUT_FILE_DIR=$(mktemp -d -t ACS_Output_DIR_XXXX ) + cat ./endpoint_list.json | envsubst > ${ENDPOINT_DIR}/endpoint_list.json + ``` + - Run Container ```bash - podman run --env $MAIN_ACS_TOKEN --env OUTPUT_FOLDER=/output -v /tmp/output:/output:Z localhost/quick_acs_app - ``` \ No newline at end of file + podman run --name acs_correlator \ + --replace \ + --userns=keep-id \ + --env MAIN_ACS_TOKEN=${MAIN_ACS_TOKEN} \ + --env ENDPOINT_LIST_JSON_PATH=/endpoint/endpoint_list.json \ + --env OUTPUT_FOLDER=/output \ + -v ${OUTPUT_FILE_DIR}:/output:z \ + -v ${ENDPOINT_DIR}:/endpoint:z \ + localhost/quick_acs_app + ``` + - If All goes well sample output should get written out to ${OUTPUT_FILE_DIR} + + - TODO: + - Example uses the [Pydantic Library to create models to export out objects relationships](https://docs.pydantic.dev/1.10/usage/exporting_models/#advanced-include-and-exclude). + - The sample relationships used for output can be seen in the [app.py](util-scripts/acs-correlation-example/app.py) on line 866 + - Will eventually extend this example to get custom relationships and export out a file. diff --git a/util-scripts/acs-correlation-example/acs_request.py b/util-scripts/acs-correlation-example/acs_request.py index 9aded2d..0d01940 100644 --- a/util-scripts/acs-correlation-example/acs_request.py +++ b/util-scripts/acs-correlation-example/acs_request.py @@ -1,6 +1,6 @@ from httpx import AsyncClient,HTTPError,NetworkError,RequestError,TimeoutException,ConnectTimeout,InvalidURL,ProtocolError,ConnectError import os -from httpx._config import SSLConfig +#from httpx._config import SSLConfig from logging import getLogger, config import typing as t import asyncio @@ -128,14 +128,29 @@ async def request_processing(full_url_path,insecure:bool=False,headers:dict=None """Send the Request and process the response""" logger.debug(f"request_processing -start: url:{full_url_path} verify_ssl:{insecure}") error=None + retry_count=3 + response_dict={"response_object":[],"error_object":None} - if params is None: - response_dict = await make_request(full_url_path,insecure,headers,params) - else: - if "pagination.limit" in params and "total_expected_count" in params: - response_dict = await request_processing_pagination(full_url_path,insecure,headers,params) + + + while retry_count > 0 and retry_count < 4: + if params is None: + response_dict = await make_request(full_url_path,insecure,headers,params) else: - response_dict = await make_request(full_url_path,insecure,headers,params) + if "pagination.limit" in params and "total_expected_count" in params: + response_dict = await request_processing_pagination(full_url_path,insecure,headers,params) + else: + response_dict = await make_request(full_url_path,insecure,headers,params) + + if response_dict["error_object"] is not None: + logger.error(f"request_processing - error: {response_dict['error_object']}") + retry_count-=1 + logger.info(f"Retrying request: {retry_count} attempts left") + logger.info(f"Sleeping for 5 seconds before retry") + await asyncio.sleep(5) + else: + break + return response_dict async def get_acs_alert(url,alert_id: str,insecure:bool=False,headers:dict=None,params:dict=None) -> dict: diff --git a/util-scripts/acs-correlation-example/app.py b/util-scripts/acs-correlation-example/app.py index 18793fc..999c3a8 100644 --- a/util-scripts/acs-correlation-example/app.py +++ b/util-scripts/acs-correlation-example/app.py @@ -861,7 +861,7 @@ async def generate_cluster_namespace_deployment_alert_output_file(): """ Generate the output for the Cluster and Deployment """ - logger.info("Generating Output for Cluster and Deployment") + logger.info("Generating Output File for Cluster-Deployment-Namespace-Alerts-Relationship") exclude_keys = { "clusters": { @@ -953,6 +953,10 @@ async def main(): # Load the ACS Endpoints result_endpoint_list = await read_parse_acs_endpoints(settings.endpoint_list_json_path) + while result_endpoint_list is None: + logger.error("Error reading endpoint list file") + logger.info("Exiting") + return for endpoint in result_endpoint_list.endpoints: await ParsedMemory.check_endpoint_valid_healthy(endpoint) diff --git a/util-scripts/acs-correlation-example/endpoint_list.json b/util-scripts/acs-correlation-example/endpoint_list.json index 14fb331..715b11d 100644 --- a/util-scripts/acs-correlation-example/endpoint_list.json +++ b/util-scripts/acs-correlation-example/endpoint_list.json @@ -2,7 +2,7 @@ "endpoints": [ { "endpoint_name": "ACS_Demo_Environment", - "endpoint_url": "https://central-rhacs-operator.apps.cluster11.sandbox2585.opentlc.com", + "endpoint_url": "${CENTRAL_API_URL}", "endpoint_url_description": "ACS API endpoint for the application to make requess to", "endpoint_token_env_variable_name": "MAIN_ACS_TOKEN", "verify_endpoint_ssl" : "False", diff --git a/util-scripts/acs-correlation-example/logging.conf b/util-scripts/acs-correlation-example/logging.conf index a166157..9b36a94 100644 --- a/util-scripts/acs-correlation-example/logging.conf +++ b/util-scripts/acs-correlation-example/logging.conf @@ -25,7 +25,7 @@ formatter=detailedFormatter args=(sys.stdout,) [formatter_normalFormatter] -format=%(asctime)s loglevel=%(levelname)-6s logger=%(name)s %(funcName)s() L%(lineno)-4d %(message)s +format=%(asctime)s loglevel=%(levelname)-6s %(funcName)s() L%(lineno)-4d %(message)s [formatter_detailedFormatter] -format=%(asctime)s loglevel=%(levelname)-6s logger=%(name)s %(funcName)s() L%(lineno)-4d %(message)s call_trace=%(pathname)s L%(lineno)-4d \ No newline at end of file +format=%(asctime)s loglevel=%(levelname)-6s %(funcName)s() L%(lineno)-4d %(message)s call_trace=%(pathname)s L%(lineno)-4d \ No newline at end of file diff --git a/util-scripts/acs-correlation-example/requirements.txt b/util-scripts/acs-correlation-example/requirements.txt index 10bc802..a8ced2a 100644 --- a/util-scripts/acs-correlation-example/requirements.txt +++ b/util-scripts/acs-correlation-example/requirements.txt @@ -1,39 +1,14 @@ -aiofiles==23.2.1 +aiofiles==24.1.0 annotated-types==0.7.0 -anyio==4.4.0 -certifi==2024.7.4 -click==8.1.7 -dnspython==2.6.1 -email_validator==2.1.1 -exceptiongroup==1.2.1 -fastapi==0.111.0 -fastapi-cli==0.0.4 +anyio==4.8.0 +certifi==2025.1.31 h11==0.14.0 -httpcore==1.0.5 -httptools==0.6.1 -httpx==0.27.0 -idna==3.7 -Jinja2==3.1.4 -markdown-it-py==3.0.0 -MarkupSafe==2.1.5 -mdurl==0.1.2 -orjson==3.10.4 -pydantic==2.7.4 -pydantic-settings==2.3.3 -pydantic_core==2.18.4 -Pygments==2.18.0 +httpcore==1.0.7 +httpx==0.28.1 +idna==3.10 +pydantic==2.10.6 +pydantic-settings==2.7.1 +pydantic_core==2.27.2 python-dotenv==1.0.1 -python-multipart==0.0.9 -PyYAML==6.0.1 -rich==13.7.1 -shellingham==1.5.4 sniffio==1.3.1 -starlette==0.37.2 -typer==0.12.3 typing_extensions==4.12.2 -ujson==5.10.0 -uuid==1.30 -uvicorn==0.30.1 -uvloop==0.19.0 -watchfiles==0.22.0 -websockets==12.0