{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://appdynamics.com/schemas/appdynamics/health-rule.json",
  "title": "AppDynamics Health Rule",
  "description": "Schema representing an AppDynamics health rule configuration that defines performance thresholds, violation conditions, and evaluation criteria for monitored entities.",
  "type": "object",
  "required": ["name", "enabled", "affects", "evalCriterias"],
  "$defs": {
    "MetricCondition": {
      "type": "object",
      "description": "A metric evaluation condition that defines a threshold for triggering a violation.",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "description": "The type of condition evaluation.",
          "enum": [
            "SINGLE_METRIC",
            "METRIC_EXPRESSION"
          ]
        },
        "metricPath": {
          "type": "string",
          "description": "The metric path to evaluate using pipe-delimited hierarchy."
        },
        "operator": {
          "type": "string",
          "description": "The comparison operator for the threshold.",
          "enum": [
            "GREATER_THAN",
            "LESS_THAN",
            "GREATER_THAN_EQUALS",
            "LESS_THAN_EQUALS",
            "EQUALS",
            "NOT_EQUALS"
          ]
        },
        "value": {
          "type": "number",
          "description": "The threshold value for comparison."
        },
        "useActiveBaseline": {
          "type": "boolean",
          "description": "Whether to use the active baseline for dynamic threshold calculation."
        },
        "baselineDeviation": {
          "type": "string",
          "description": "The baseline deviation direction for dynamic thresholds.",
          "enum": [
            "ABOVE",
            "BELOW",
            "ABOVE_OR_BELOW"
          ]
        },
        "baselineDeviations": {
          "type": "number",
          "description": "The number of standard deviations from baseline to trigger a violation.",
          "minimum": 0
        }
      }
    }
  },
  "properties": {
    "id": {
      "type": "integer",
      "description": "The internal numeric identifier for the health rule."
    },
    "name": {
      "type": "string",
      "description": "The name of the health rule.",
      "minLength": 1,
      "maxLength": 255
    },
    "enabled": {
      "type": "boolean",
      "description": "Whether the health rule is currently enabled."
    },
    "useDataFromLastNMinutes": {
      "type": "integer",
      "description": "The evaluation time window in minutes.",
      "minimum": 1,
      "maximum": 1440
    },
    "waitTimeAfterViolation": {
      "type": "integer",
      "description": "Time in minutes to wait after a violation before re-evaluating.",
      "minimum": 0
    },
    "scheduleName": {
      "type": "string",
      "description": "The schedule name that determines when this health rule is active.",
      "default": "Always"
    },
    "affects": {
      "type": "object",
      "description": "Defines which entities are affected by this health rule.",
      "required": ["affectedEntityType"],
      "properties": {
        "affectedEntityType": {
          "type": "string",
          "description": "The type of entity this health rule evaluates.",
          "enum": [
            "OVERALL_APPLICATION",
            "BUSINESS_TRANSACTION",
            "TIER_NODE",
            "BACKEND",
            "INFORMATION_POINT",
            "CUSTOM",
            "MOBILE_APPLICATION",
            "BROWSER_APPLICATION"
          ]
        },
        "affectedBusinessTransactions": {
          "type": "object",
          "description": "Business transaction selection criteria.",
          "properties": {
            "businessTransactionScope": {
              "type": "string",
              "description": "The scope for selecting business transactions.",
              "enum": [
                "ALL_BUSINESS_TRANSACTIONS",
                "SPECIFIC_BUSINESS_TRANSACTIONS",
                "BUSINESS_TRANSACTIONS_MATCHING_PATTERN"
              ]
            }
          }
        },
        "affectedNodes": {
          "type": "object",
          "description": "Node selection criteria.",
          "properties": {
            "affectedNodeScope": {
              "type": "string",
              "description": "The scope for selecting nodes.",
              "enum": [
                "ALL_NODES",
                "SPECIFIC_NODES",
                "NODES_MATCHING_PATTERN",
                "NODES_OF_SPECIFIC_TIERS"
              ]
            }
          }
        }
      }
    },
    "evalCriterias": {
      "type": "object",
      "description": "The evaluation criteria containing critical and warning conditions.",
      "properties": {
        "criticalCriteria": {
          "type": "object",
          "description": "The critical severity evaluation criteria.",
          "properties": {
            "conditionAggregationType": {
              "type": "string",
              "description": "How to aggregate multiple conditions.",
              "enum": ["ALL", "ANY", "CUSTOM"]
            },
            "conditions": {
              "type": "array",
              "description": "The list of metric conditions for critical violations.",
              "items": {
                "$ref": "#/$defs/MetricCondition"
              }
            }
          }
        },
        "warningCriteria": {
          "type": "object",
          "description": "The warning severity evaluation criteria.",
          "properties": {
            "conditionAggregationType": {
              "type": "string",
              "description": "How to aggregate multiple conditions.",
              "enum": ["ALL", "ANY", "CUSTOM"]
            },
            "conditions": {
              "type": "array",
              "description": "The list of metric conditions for warning violations.",
              "items": {
                "$ref": "#/$defs/MetricCondition"
              }
            }
          }
        }
      }
    }
  }
}
