writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
sap-maintenance-handlerHandles Azure scheduled maintenance events. Detects VM reboot/redeploy events via Azure Scheduled Events API, coordinates graceful SAP shutdown, and validates recovery. Requires command proxy for VM operations.
Independent GitHub snapshot · Automated classification · Original documentation governs
All environment-specific values (subscription ID, AMS workspace ID, proxy URLs, API keys, SAP landscape) are provided via the Team Onboarding instructions. The agent reads these from the onboarding context at runtime. Do not hardcode environment values in this skill.
Authentication: Use the agent's built-in tools (RunAzCliReadCommands, GetArmResourceAsJson, QueryLogAnalyticsByWorkspaceId, GetMetricTimeSeriesElementsForAzureResource) for Azure API calls. These authenticate automatically via the agent's Managed Identity.
Data Reuse (AAU Optimization): Before calling any API or proxy, check if the data was already retrieved earlier in this conversation. Reuse landscape registry, VM power states, config files, and AMS query results from context. Do not re-fetch data that is already available.
Config reads & proxy fallback: Stored SAP/OS configs are read directly from the sap-configs blob container using the agent's own Managed Identity (--auth-mode login) — there is no config proxy. The MCP command proxy is optional and runs only live VM commands; if it is not deployed or errors (timeout, 5xx, unreachable), continue with stored blob configs + Azure-native sources (AMS, ARM API, Azure Monitor). Never block the skill on the proxy.
This skill adapts automatically based on what infrastructure is listed in the ## Deployed Infrastructure section of Team Onboarding.
sap-configs blob container to pre-validate the system is in a safe state before the maintenance window (HSR sync OK, no long-running backup pinned in global.ini, etc.). Still cannot execute remediation actions without the proxy.sap_stop_graceful, hdb_stop, hdb_start, sap_start) through the proxy, subject to the T4 guardrails below.sap_stop_graceful, hdb_stop, hdb_start, sap_startT4_ENABLED=falseIMPORTANT — Azure API Access: Do NOT use IMDS tokens (169.254.169.254) or ManagedIdentityCredential — they are not available in the agent sandbox. Instead:
GetArmResourceAsJson or RunAzCliReadCommands toolsQueryLogAnalyticsByWorkspaceId toolGetMetricTimeSeriesElementsForAzureResource toolsap-sre-proxy MCP connector) — never make direct HTTP or proxy calls# Use the built-in tools above for Azure API access.
import json
from datetime import datetime, timezone
# SUB_ID: Use subscription_id from Team Onboarding
# All VM commands are executed via the SAP Command Runner skill (MCP run_command / run_batch).
# This skill determines WHAT to do; SAP Command Runner does HOW. Never call the proxy directly.
# Stored configs (pre-checks) are read directly from the sap-configs blob with the agent MI
# (`az storage blob ... --auth-mode login`) — only when a Storage Account is listed.
To execute VM commands: Invoke the SAP Command Runner skill. Do NOT call the command proxy directly.
Example invocations:
sap_stop_graceful, sidadm=<sid>adm, sid=<SID>hdb_stop, sidadm=<sid>admhdb_start, sidadm=<sid>admsap_start, sidadm=<sid>adm, sid=<SID>crm_maintenance_oncrm_maintenance_offThe agent checks Azure Scheduled Events API via the SAP Command Runner skill:
# Invoke SAP Command Runner with command_id="scheduled_events"
# This reads http://169.254.169.254/metadata/scheduledevents on the VM
def check_scheduled_events(vm_name, rg):
# Invoke SAP Command Runner skill
pass
Response format from Azure:
{
"Events": [{
"EventId": "...",
"EventType": "Reboot",
"ResourceType": "VirtualMachine",
"Resources": ["AB1vm"],
"EventStatus": "Scheduled",
"NotBefore": "2026-05-09T03:00:00Z"
}]
}
The action plan keys off deployment (see Step 2) and must also respect architecture:
def determine_maintenance_action(vm_name, event_type, landscape):
"""Determine the correct maintenance sequence based on topology (deployment field)."""
system = find_system_for_vm(vm_name, landscape)
deployment = system.get("deployment", "standalone") # standalone | distributed | high-availability | disaster-recovery
if deployment in ("standalone", "distributed"):
# No cluster: graceful stop, let Azure reboot, auto-start after
return {
"pre_actions": ["sap_stop_graceful", "hdb_stop"],
"post_actions": ["hdb_start", "sap_start"],
"takeover": False
}
elif deployment in ("high-availability", "disaster-recovery"):
# HA/DR: if this VM is the HSR/ASCS primary, trigger takeover to the secondary first
vm = find_vm(system, vm_name)
is_primary = vm.get("ha_role") == "primary"
return {
"pre_actions": ["sap_stop_graceful", "hdb_stop"],
"post_actions": ["hdb_start", "sap_start"],
"takeover": is_primary,
"takeover_target": next((v["name"] for v in system["vms"] if v.get("ha_role") == "secondary"), None)
}
For standalone / distributed (no cluster):
sap_stop_graceful, sidadm=ab1adm, sid=AB1hdb_stop, sidadm=db1admhdb_start, sidadm=db1admsap_start, sidadm=ab1adm, sid=AB1For high-availability / disaster-recovery (clustered) — for scale-out, repeat per DB node preserving quorum:
crm_maintenance_oncrm_maintenance_offSend Teams notification with full action log:
✅ SAP Maintenance Autopilot — AB1
Azure scheduled maintenance handled automatically:
03:00 Scheduled Event detected: Reboot on AB1vm (NotBefore: 03:15)
03:01 SAP graceful shutdown initiated (AB1)
03:02 HANA graceful shutdown initiated (DB1)
03:03 Maintenance event acknowledged
03:15 VM rebooted by Azure
03:17 VM back online
03:18 HANA started successfully (7 services GREEN)
03:19 SAP started successfully (all processes GREEN)
03:20 Config validation: 59/59 PASS (no drift)
Total downtime: 2 minutes (03:15 - 03:17)
Without autopilot: estimated 15-30 minutes unplanned downtime