07 Oct 2024 02:15 PM
Hello,
I’m currently working with the Dynatrace API (v2) to retrieve namespace entity IDs that are associated with a specific Kubernetes cluster. The goal is to generate a deep link based on the namespace and cluster combination.
I’m using the following entitySelector query:
type(CLOUD_APPLICATION_NAMESPACE),entityName.equals("namespace_name"),toRelationships.isCluster(type(KUBERNETES_CLUSTER),entityName.equals("cluster_name"))
While this query works in theory, I’m encountering issues where the namespace is not being validated correctly against the cluster. Despite the namespace existing within the specified cluster, the API returns no entities, or I receive a 404 error stating that the namespace was not found in the cluster.
Here’s the relevant portion of my code for fetching the namespace entity ID:
def get_namespace_entity_id(namespace_name, cluster_name):
url = f"{dynatrace_env}/api/v2/entities"
headers = {
"Authorization": f"Api-Token {api_token}"
}
params = {
"entitySelector": (
f"type(CLOUD_APPLICATION_NAMESPACE),entityName.equals(\"{namespace_name}\"),"
f"toRelationships.isCluster(type(KUBERNETES_CLUSTER),entityName.equals(\"{cluster_name}\"))"
)
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
entities = response.json().get('entities', [])
if entities:
return entities[0]['entityId'] # Return the first matching entity ID
else:
return None # No matching entity found
else:
print(f"Request failed with status code {response.status_code}")
print("Response content:", response.text)
return None
Even though I’ve specified the correct cluster and namespace names, the query doesn't seem to work as expected. Has anyone encountered this issue when using toRelationships.isCluster in entitySelector queries, and how can I resolve this to properly validate the namespace under the specified cluster?
Any help or insights would be appreciated!
07 Oct 2024 03:18 PM
Hi @vignesh179
You can verify the below points:
KR,
Peter.
07 Oct 2024 04:48 PM
Hi Peter,
Thank you for your suggestions. I have verified the following:
Despite these checks, I'm still encountering the same issue. If you have any additional insights or troubleshooting steps, I would greatly appreciate your help.
Best regards,
Vignesh
07 Oct 2024 05:03 PM
Hi @Peter_Youssef
This is my terminal error message,
curl : {"error":{"code":400,"message":"Constraints
violated.","constraintViolations":[{"path":"entitySelector","message":"Unknown predicate name
toRelationships.isCluster","parameterLocation":"QUERY","location":null}]}}