Skip to main content

Hiding Root Causes

You may want to hide a root cause for a time period if you are not planning on addressing it immediately or if you are performing maintenance and the behavior is expected.

The recommended way to hide a specific root cause is to use Entity Configs of type IgnoreRC. To avoid overwriting existing configuration for that entity, you should:

  1. Query the current IgnoreRC config for the entity.
  2. Merge your new rule with any existing entries.
  3. Call the CreateEntityConfigs mutation with the combined config.
Prerequisite

Each example below reuses the helper utilities defined in the Authentication and GraphQL Clients sections (get_causely_access_token, create_graphql_client, post_query, and their language equivalents).

import os
import json

# Reuse helpers defined earlier in this guide:
# - get_causely_access_token
# - create_graphql_client
# - post_query

GET_CONFIGS_QUERY = """
query GetEntityConfigs($entityId: String!, $configType: String!) {
entityConfigs(entityId: $entityId, configType: $configType) {
entityId
type
data
}
}
"""

CREATE_CONFIGS_MUTATION = """
mutation CreateEntityConfigs($entityConfigs: [EntityConfigInput!]!) {
createEntityConfigs(entityConfigs: $entityConfigs) {
entityId
type
data
}
}
"""

def load_existing_ignore_rc_configs(client, entity_id, config_type="IgnoreRC"):
"""Fetch existing IgnoreRC configs and return them as a Python list."""
variables = {"entityId": entity_id, "configType": config_type}
result = post_query(client, GET_CONFIGS_QUERY, variables)

entries = []
for cfg in result.get("entityConfigs", []):
data_str = cfg.get("data") or "[]"
try:
entries.extend(json.loads(data_str))
except json.JSONDecodeError:
# If data is malformed, skip rather than failing the whole operation
continue
return entries

def save_ignore_rc_configs(client, entity_id, configs, config_type="IgnoreRC"):
"""Persist the merged IgnoreRC configs back to Causely."""
variables = {
"entityConfigs": [{
"entityId": entity_id,
"type": config_type, # If your schema uses ENUMs, pass the enum instead
"data": json.dumps(configs), # Must be a JSON string
}]
}
return post_query(client, CREATE_CONFIGS_MUTATION, variables)

if __name__ == "__main__":
# Get credentials from environment
cid, secret = os.getenv("CAUSELY_CLIENT_ID"), os.getenv("CAUSELY_CLIENT_SECRET")
if not cid or not secret:
raise EnvironmentError("Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET")

# Get access token and create GraphQL client
token = get_causely_access_token(cid, secret)
client = create_graphql_client(token)

# Target entity and root cause name you want to hide
# Replace these example values with your actual entity ID and root cause name
entity_id = "47c29d23-9f57-5d47-9f91-a72815edc8cf"
defect_name_to_hide = "Malfunction"

# 1) Load existing IgnoreRC configuration (if any)
existing_configs = load_existing_ignore_rc_configs(client, entity_id)

# 2) Add or update the entry for this root cause without losing existing ones
new_entry = {
"DefectName": defect_name_to_hide,
# Set an appropriate expiry time for the ignore rule
"UntilTime": "2025-11-15T10:51:00-04:00",
}

# Avoid adding duplicate entries for the same defect name
merged_configs = [
cfg for cfg in existing_configs
if cfg.get("DefectName") != defect_name_to_hide
]
merged_configs.append(new_entry)

# 3) Save the merged configuration back using the mutation
result = save_ignore_rc_configs(client, entity_id, merged_configs)
print(json.dumps(result, indent=2))