# you can disable an alarm notification by setting the 'to' line to: silent

# --- Run Failure Rate ---

# Run failure percentage (0-100%). High is bad.
# AMBA: RunFailurePercentage > 0 is Sev1

 template: am_logic_apps_run_failure_rate
       on: azure_monitor.logic_apps.run_failure_rate
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of failure_rate
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (1) : (5))
     crit: $this > (($status == $CRITICAL) ? (5) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps run failure rate on ${label:resource_name}
     info: Percentage of workflow runs failing on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Run Failures (absolute count) ---

# Failed runs rate. Any sustained failures need attention.

 template: am_logic_apps_runs_failed
       on: azure_monitor.logic_apps.run_lifecycle
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of failed
    units: runs/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps failed runs on ${label:resource_name}
     info: Rate of failed workflow runs on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Run Latency ---

# Overall run latency (seconds). High latency indicates slow workflows.

 template: am_logic_apps_run_latency
       on: azure_monitor.logic_apps.run_latency
    class: Latency
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of all
    units: seconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (30) : (60))
     crit: $this > (($status == $CRITICAL) ? (60) : (120))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps run latency on ${label:resource_name}
     info: Average workflow run latency on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Run Throttling ---

# Throttled run events indicate the workflow is hitting
# Azure rate limits.

 template: am_logic_apps_run_throttled
       on: azure_monitor.logic_apps.run_throttling
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned
    units: events/s
    every: 1m
     warn: $this > (($status >= $WARNING) ? (0) : (1))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps run throttling on ${label:resource_name}
     info: Rate of throttled run events on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Throttling indicates Azure rate limits are being hit
       to: sysadmin

# --- Action Failures ---

# Failed actions rate. Failing actions cause workflow failures.

 template: am_logic_apps_actions_failed
       on: azure_monitor.logic_apps.action_lifecycle
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of failed
    units: actions/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps failed actions on ${label:resource_name}
     info: Rate of failed actions on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Action Latency ---

# Average action latency. High values indicate slow connectors
# or backend dependencies.

 template: am_logic_apps_action_latency
       on: azure_monitor.logic_apps.action_latency
    class: Latency
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of all
    units: seconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (15) : (30))
     crit: $this > (($status == $CRITICAL) ? (30) : (60))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps action latency on ${label:resource_name}
     info: Average action latency on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Action Throttling ---

# Throttled action events indicate connectors or actions
# are hitting Azure rate limits.

 template: am_logic_apps_action_throttled
       on: azure_monitor.logic_apps.action_throttling
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of total
    units: events/s
    every: 1m
     warn: $this > (($status >= $WARNING) ? (0) : (1))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps action throttling on ${label:resource_name}
     info: Rate of throttled action events on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Throttling indicates connector rate limits are being hit
       to: sysadmin

# --- Trigger Failures ---

# Failed triggers prevent workflows from starting.

 template: am_logic_apps_triggers_failed
       on: azure_monitor.logic_apps.trigger_lifecycle
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of failed
    units: triggers/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps failed triggers on ${label:resource_name}
     info: Rate of failed triggers on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Failed triggers prevent workflows from executing
       to: sysadmin

# --- Trigger Latency ---

# Overall trigger latency. High values indicate slow polling
# or webhook delays.

 template: am_logic_apps_trigger_latency
       on: azure_monitor.logic_apps.trigger_latency
    class: Latency
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of all
    units: seconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (15) : (30))
     crit: $this > (($status == $CRITICAL) ? (30) : (60))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps trigger latency on ${label:resource_name}
     info: Average trigger latency on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Trigger Throttling ---

# Throttled trigger events indicate polling or webhook triggers
# are hitting Azure rate limits.

 template: am_logic_apps_trigger_throttled
       on: azure_monitor.logic_apps.trigger_throttling
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of total
    units: events/s
    every: 1m
     warn: $this > (($status >= $WARNING) ? (0) : (1))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps trigger throttling on ${label:resource_name}
     info: Rate of throttled trigger events on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Throttling indicates trigger rate limits are being hit
       to: sysadmin

# --- AI Agent Token Overflow ---

# Completion token overflow events indicate AI agent responses
# are exceeding token limits (AI-enabled Logic Apps only).

 template: am_logic_apps_completion_token_overflow
       on: azure_monitor.logic_apps.agent
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of completion_overflow
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (1))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps completion token overflow on ${label:resource_name}
     info: Rate of completion token overflow events on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Indicates AI agent responses are exceeding token limits
       to: sysadmin

# Prompt token overflow events indicate AI agent prompts
# are exceeding token limits (AI-enabled Logic Apps only).

 template: am_logic_apps_prompt_token_overflow
       on: azure_monitor.logic_apps.agent
    class: Errors
     type: Other
component: Logic Apps
   lookup: average -5m unaligned of prompt_overflow
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (1))
    delay: down 5m multiplier 1.5 max 1h
  summary: Logic Apps prompt token overflow on ${label:resource_name}
     info: Rate of prompt token overflow events on Logic App ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Indicates AI agent prompts are exceeding token limits
       to: sysadmin
