<!-- Auto-generated for OpenClaw by pack-openclaw. Notes for OpenClaw users:
- Claude Code dynamic expressions (!`...`) in this file are NOT evaluated by OpenClaw
and appear as literal text. Run them manually at the start of the workflow.
- Invoke this skill only via slash command (e.g. /amg-check-key-vault). Auto-invocation is
disabled on Claude Code but not on OpenClaw. -->
<h2>OpenClaw Setup (one-time)</h2>
<p>This skill calls MCP tools prefixed with <code>mcp__amg__*</code>, so OpenClaw must have an MCP server registered under the exact name <strong><code>amg</code></strong>. Run this once per workspace before invoking the skill:</p>
<pre><code class="language-bash">openclaw mcp set amg '{"url":"https://<your-grafana-instance>/api/azure-mcp","transport":"streamable-http","headers":{"Authorization":"Bearer <your-token>"}}'
</code></pre>
<p>Replace <code><your-grafana-instance></code> with your Azure Managed Grafana endpoint and <code><your-token></code> with a valid Grafana service-account token (starts with <code>glsa_</code>). The server name <strong>must</strong> be <code>amg</code> — the skill's <code>allowed-tools</code> reference <code>mcp__amg__*</code> and will not find tools under any other name.</p>
<p>Verify the server is registered:</p>
<pre><code class="language-bash">openclaw mcp list
</code></pre>
<blockquote>
<p>Official skill source: https://github.com/Azure/amg-skills</p>
</blockquote>
<h2>Runtime Context</h2>
<ul>
<li>Current UTC time: !<code>date -u +%Y-%m-%dT%H:%M:%SZ</code></li>
<li>Config: !<code>cat memory/amg-check-key-vault/config.md 2>/dev/null || echo "NOT_CONFIGURED"</code></li>
<li>Prior report: !<code>[ -f memory/amg-check-key-vault/report.md ] && echo "exists ($(grep -c '^### KV-' memory/amg-check-key-vault/report.md) bugs documented)" || echo "not found"</code></li>
<li>Arguments: time-range=$0, subscription-override=$1</li>
</ul>
<blockquote>
<p><strong>Known Issues</strong>: Before presenting findings, cross-reference results against <code>memory/amg-check-key-vault/report.md</code>.</p>
</blockquote>
<h2>Azure Key Vault Health Check</h2>
<p>Analyze Azure Key Vault health using a <strong>two-phase approach</strong>: a single <code>amgmcp_pulse_check</code> call for fleet-wide summary, followed by targeted deep dives into the <strong>top 7 most interesting vaults</strong> only.</p>
<h2>Critical Constraints</h2>
<ul>
<li><strong>Do NOT use subagents (Agent tool) for MCP queries.</strong> Subagents do not have access to MCP tools. All MCP tool calls must be made directly from the main conversation context.</li>
<li><strong>Deep dive limit: at most 7 vaults.</strong> Select the most interesting vaults from pulse check results. Do not deep-dive the entire fleet.</li>
<li><strong>Time format</strong>: ISO 8601 UTC with explicit <code>from</code>/<code>to</code> — NEVER use <code>timespan</code> (it causes errors).</li>
<li><strong>Parallelism cap</strong>: 30 concurrent MCP calls per batch. Reduce to 4-5 if rate-limited.</li>
</ul>
<h2>Prerequisites</h2>
<ul>
<li>An AMG-MCP server must be connected (the <code>allowed-tools</code> frontmatter references the MCP server name — update it if your server has a different name)</li>
<li>The MCP server's Grafana service account token environment variable must be set</li>
</ul>
<h2>Configuration</h2>
<p><strong>If Config shows <code>NOT_CONFIGURED</code></strong>: Run First-Run Setup at the bottom of this file, then return here.</p>
<p><strong>If Config is populated</strong>: Extract the datasource UID and subscription ID(s) from the pre-loaded Runtime Context above and use them for all queries. Use <code>$1</code> as the subscription override if provided.</p>
<ul>
<li><strong>Datasource UID</strong>: from <code>## Azure Monitor Datasource</code> > <code>UID</code></li>
<li><strong>Subscription ID(s)</strong>: from <code>## Subscriptions</code> (or <code>$1</code> if provided)</li>
<li><strong>Resource Type</strong>: <code>microsoft.keyvault/vaults</code> (lowercase)</li>
<li><strong>ARM ID template</strong>: <code>/subscriptions/{SUB}/resourceGroups/{RG}/providers/Microsoft.KeyVault/vaults/{name}</code></li>
</ul>
<h2>Time Range</h2>
<p>Default is 7 days (<code>pastDays: 7</code>) for pulse check and deep-dive metrics, 24 hours for resource logs. If the user specifies a different range via <code>$ARGUMENTS[0]</code> (e.g., <code>/amg-check-key-vault 3d</code>), adjust accordingly. For resource log queries, keep the range narrow (1-2 days) to avoid timeouts.</p>
<h2>Workflow</h2>
<h3>Phase 1: Validate Datasource & Discover Vaults</h3>
<p><strong>Step 1a: Validate Datasource</strong></p>
<p>Call <code>amgmcp_datasource_list</code> with no parameters.</p>
<p>Search the results for a datasource with <code>type</code> equal to <code>grafana-azure-monitor-datasource</code>. Extract its <code>uid</code>.</p>
<ul>
<li>If it matches the configured UID, proceed.</li>
<li>If it differs, update <code>memory/amg-check-key-vault/config.md</code>, warn the user, and use the new UID.</li>
<li>If no Azure Monitor datasource is found, abort with a clear error.</li>
</ul>
<p><strong>Step 1b: Discover All Key Vaults</strong></p>
<p>Call <code>amgmcp_query_resource_graph</code> once using the configured datasource UID and subscription ID(s):</p>
<pre><code>azureMonitorDatasourceUid: {DATASOURCE_UID}
query: |
resources
| where type == 'microsoft.keyvault/vaults'
| where subscriptionId in ({SUBSCRIPTION_IDS})
| project name, resourceGroup, location, subscriptionId, sku=properties.sku.name, enableSoftDelete=properties.enableSoftDelete, enablePurgeProtection=properties.enablePurgeProtection, provisioningState=properties.provisioningState
| order by location asc, name asc
</code></pre>
<p>Replace <code>{SUBSCRIPTION_IDS}</code> with the configured subscription IDs formatted as comma-separated quoted strings (e.g., <code>'sub-id-1', 'sub-id-2'</code>).</p>
<p><strong>Constructing the ARM resource ID</strong>: Use subscriptionId from each row:</p>
<pre><code>/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.KeyVault/vaults/{name}
</code></pre>
<p><strong>Region summary</strong>: Derive from the vault list by counting vaults per unique <code>location</code> value.</p>
<p><strong>SKU summary</strong>: Count vaults by <code>sku</code> (standard vs premium).</p>
<p>Note any vaults not in "Succeeded" provisioning state — flag them immediately.</p>
<p>If zero vaults are found, report "No Key Vaults found" and stop.</p>
<h3>Phase 2: Fleet-Wide Pulse Check</h3>
<p>Call <code>amgmcp_pulse_check</code> once to get a summary across all key vaults:</p>
<pre><code>azureMonitorDatasourceUid: {DATASOURCE_UID}
pastDays: 7
scenarios: keyvault_summary
</code></pre>
<p>If <code>$1</code> provides a subscription ID, add <code>subscriptionId</code> to scope the scan. Otherwise, if the config has a single subscription, pass it.</p>
<p><strong>After the pulse check, verify:</strong></p>
<ol>
<li>The number of scanned resources is close to the Phase 1 vault count.</li>
<li>The scenario shows <code>status: "completed"</code>.</li>
<li>If errors occurred, retry once. If still failing, note the failure in the report.</li>
</ol>
<p><strong>Cross-reference pulse check results with Phase 1 inventory</strong> to enrich each vault with its resource group, region, and SKU from the Resource Graph data.</p>
<h3>Phase 3: Top 7 Deep Dive</h3>
<p>From the pulse check results, <strong>select at most 7 vaults</strong> for detailed investigation. Prioritize vaults with the most interesting signals:</p>
<ol>
<li><strong>Availability drops</strong> — any vault below 99.9% availability</li>
<li><strong>Highest error counts</strong> — vaults with the most non-Success responses (especially 401, 403, 429)</li>
<li><strong>Highest latency</strong> — vaults with the highest average API latency</li>
<li><strong>Throttling (429)</strong> — vaults showing rate-limiting responses</li>
<li><strong>Diversity</strong> — prefer selecting vaults from different regions to maximize coverage</li>
</ol>
<p>If the pulse check shows fewer than 7 vaults with notable signals, only deep-dive those that have something worth investigating. Do not pad to 7.</p>
<p>If the pulse check shows the entire fleet is healthy with no notable signals, skip Phase 3 entirely and report the fleet as healthy.</p>
<h4>Step 3a: Deep Metrics</h4>
<p>For each selected vault, query these metrics <strong>in parallel</strong> using <code>amgmcp_query_resource_metric</code>. Compute <code>from</code> (matching <code>pastDays</code> from Phase 2) and <code>to</code> (now) in ISO 8601 UTC.</p>
<table>
<thead>
<tr>
<th>Metric Name</th>
<th>Aggregation</th>
<th>Interval</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td><code>Availability</code></td>
<td><code>Average</code></td>
<td>PT6H</td>
<td>Availability trend</td>
</tr>
<tr>
<td><code>ServiceApiLatency</code></td>
<td><code>Average</code></td>
<td>PT6H</td>
<td>Average API latency</td>
</tr>
<tr>
<td><code>ServiceApiLatency</code></td>
<td><code>Maximum</code></td>
<td>PT6H</td>
<td>Tail latency spikes</td>
</tr>
<tr>
<td><code>ServiceApiHit</code></td>
<td><code>Total</code></td>
<td>PT6H</td>
<td>Total API call volume</td>
</tr>
<tr>
<td><code>ServiceApiResult</code> (errors)</td>
<td><code>Total</code></td>
<td>PT6H</td>
<td>Error count (<code>filter: StatusCode ne '200'</code>)</td>
</tr>
<tr>
<td><code>ServiceApiResult</code> (throttled)</td>
<td><code>Total</code></td>
<td>PT6H</td>
<td>Throttling count (<code>filter: StatusCode eq '429'</code>)</td>
</tr>
<tr>
<td><code>ServiceApiResult</code> (auth failures)</td>
<td><code>Total</code></td>
<td>PT6H</td>
<td>Auth errors (<code>filter: StatusCode eq '401' or StatusCode eq '403'</code>)</td>
</tr>
<tr>
<td><code>SaturationShoebox</code></td>
<td><code>Average</code></td>
<td>PT6H</td>
<td>Vault capacity saturation</td>
</tr>
</tbody></table>
<p>All 7 vaults can be queried in parallel (7 vaults x 8 metrics = 56 calls, within the 30-call batch cap when split into 2 batches).</p>
<p><strong>Correlation analysis</strong> — when analyzing metrics together:</p>
<ul>
<li><strong>High latency + high API hits</strong> = vault under load, possibly approaching throttle limits</li>
<li><strong>High latency + throttling (429)</strong> = vault is being rate-limited, clients retrying</li>
<li><strong>High errors + normal latency</strong> = client-side issues (bad auth, missing secrets)</li>
<li><strong>High 401/403 + specific time window</strong> = key rotation event or misconfigured client</li>
<li><strong>Availability drop + high errors</strong> = sustained vault issue</li>
<li><strong>High saturation + high API hits</strong> = vault approaching transaction limits</li>
<li><strong>Dormant (all empty)</strong> = no traffic, investigate if orphaned</li>
</ul>
<h4>Step 3b: Resource Logs</h4>
<p>For each selected vault, query Key Vault resource logs using <code>amgmcp_query_resource_log</code>. Keep time range to 1-2 days.</p>
<p><strong>Log Query 1: Failed requests by status code</strong></p>
<pre><code class="language-kql">AzureDiagnostics
| where ResourceType == "VAULTS"
| where TimeGenerated between (datetime(<START>) .. datetime(<END>))
| where httpStatusCode_d >= 400
| summarize count() by httpStatusCode_d, OperationName, bin(TimeGenerated, 1h)
| order by TimeGenerated asc
</code></pre>
<p><strong>Log Query 2: Top error operations</strong></p>
<pre><code class="language-kql">AzureDiagnostics
| where ResourceType == "VAULTS"
| where TimeGenerated between (datetime(<START>) .. datetime(<END>))
| where httpStatusCode_d >= 400
| summarize count() by OperationName, httpStatusCode_d, ResultSignature
| order by count_ desc
| take 30
</code></pre>
<p><strong>Log Query 3: Throttled requests (429) over time</strong></p>
<pre><code class="language-kql">AzureDiagnostics
| where ResourceType == "VAULTS"
| where TimeGenerated between (datetime(<START>) .. datetime(<END>))
| where httpStatusCode_d == 429
| summarize count() by OperationName, bin(TimeGenerated, 1h)
| order by TimeGenerated asc
</code></pre>
<p><strong>Log Query 4: Request volume trend</strong></p>
<pre><code class="language-kql">AzureDiagnostics
| where ResourceType == "VAULTS"
| where TimeGenerated between (datetime(<START>) .. datetime(<END>))
| summarize
TotalRequests=count(),
FailedRequests=countif(httpStatusCode_d >= 400),
ThrottledRequests=countif(httpStatusCode_d == 429),
AvgDurationMs=round(avg(DurationMs), 2)
by bin(TimeGenerated, 1h)
| order by TimeGenerated asc
</code></pre>
<p><strong>Log Query 5: Authentication failures</strong></p>
<pre><code class="language-kql">AzureDiagnostics
| where ResourceType == "VAULTS"
| where TimeGenerated between (datetime(<START>) .. datetime(<END>))
| where httpStatusCode_d in (401, 403)
| summarize count() by OperationName, CallerIPAddress, identity_claim_appid_g
| order by count_ desc
| take 20
</code></pre>
<blockquote>
<p><strong>Note</strong>: If <code>AzureDiagnostics</code> with <code>ResourceType == "VAULTS"</code> returns no data, diagnostic settings may not be configured. Note it and skip logs for that vault.</p>
</blockquote>
<h2>Classification</h2>
<table>
<thead>
<tr>
<th>Severity</th>
<th>Criteria</th>
</tr>
</thead>
<tbody><tr>
<td><strong>CRITICAL</strong></td>
<td>Availability avg < 99.0%, OR SaturationShoebox avg > 75%</td>
</tr>
<tr>
<td><strong>WARNING</strong></td>
<td>Availability avg < 99.9%, OR ServiceApiLatency avg > 200ms, OR sustained 429 throttling across multiple time windows, OR sustained 401/403 errors</td>
</tr>
<tr>
<td><strong>DORMANT</strong></td>
<td>All metrics return empty timeSeries (no traffic in scan period)</td>
</tr>
<tr>
<td><strong>HEALTHY</strong></td>
<td>All metrics within normal ranges</td>
</tr>
</tbody></table>
<h2>Analysis Guidance</h2>
<p>For known patterns, deep-dive queries, and correlation techniques, see reference/analysis-patterns.md.</p>
<p>For optional deep-dive queries, see reference/deep-dive-queries.md.</p>
<h2>Output Format</h2>
<p>Present a summary report with these sections:</p>
<h3>1. Fleet Inventory</h3>
<p>Vault count by region, subscription, and SKU. Flag any vaults not in "Succeeded" provisioning state. Note soft-delete and purge-protection status.</p>
<h3>2. Pulse Check Summary</h3>
<p>Fleet-wide summary from the <code>keyvault_summary</code> pulse check:</p>
<ul>
<li>Total vaults scanned and scan status</li>
<li>Key fleet-wide metrics (availability, latency, API hits, error counts)</li>
<li>Breakdown by health status (healthy / warning / critical / dormant)</li>
<li>Which vaults were selected for deep dive and why each was chosen</li>
</ul>
<h3>3. Deep Dive Findings (Top 7)</h3>
<p>For each selected vault:</p>
<ul>
<li><strong>Metric timeline</strong>: Availability, API latency, API hits, saturation over the scan window</li>
<li><strong>Anomaly characterization</strong>: spike vs sustained, onset time, duration, recovery</li>
<li><strong>Correlation analysis</strong>: which metrics moved together</li>
<li><strong>Error rate</strong>: error results / total API hits percentage</li>
</ul>
<h3>4. Resource Log Findings</h3>
<p>For each deep-dived vault:</p>
<ul>
<li><strong>Error summary</strong>: top error status codes, affected operations, throttling timeline</li>
<li><strong>Latency analysis</strong>: slow operations by type</li>
<li><strong>Authentication failures</strong>: if any, source IPs and application IDs</li>
</ul>
<h3>5. Known Issue Cross-Reference</h3>
<p>Compare findings against <code>memory/amg-check-key-vault/report.md</code>. For each known bug, state: still active / improving / worsening / resolved.</p>
<h3>6. Action Items</h3>
<p>Prioritized list:</p>
<ul>
<li><strong>Critical</strong>: vaults with availability < 99.0% or saturation > 75%</li>
<li><strong>High</strong>: vaults with sustained throttling (429), high latency, or auth failures</li>
<li><strong>Medium</strong>: vaults with elevated latency, intermittent errors, or approaching saturation</li>
<li><strong>Low</strong>: dormant vaults (investigate if orphaned), informational items</li>
</ul>
<h2>Update Known Issues</h2>
<p>After presenting findings, update <code>memory/amg-check-key-vault/report.md</code>:</p>
<ol>
<li><strong>Read the current file</strong> (create if it doesn't exist).</li>
<li><strong>Update status</strong> of existing bugs based on today's telemetry.</li>
<li><strong>Add new bugs</strong> with: severity, vault name, region, metric evidence, log evidence, root cause, recommended action.</li>
<li><strong>Update the "Updated" date</strong> in the header.</li>
</ol>
<p>Only add genuine issues: sustained availability drops, persistent throttling, high error rates, or latency degradation.</p>
<h2>Error Handling</h2>
<p>See <strong>${CLAUDE_SKILL_DIR}/reference/error-handling.md</strong> for the full recovery table.</p>
<h2>Reference</h2>
<ul>
<li>Key Vault resource type: <code>Microsoft.KeyVault/vaults</code></li>
<li>ARM ID template: <code>/subscriptions/{SUB}/resourceGroups/{RG}/providers/Microsoft.KeyVault/vaults/{name}</code></li>
<li>Resource log table: <code>AzureDiagnostics</code> (with <code>ResourceType == "VAULTS"</code>)</li>
<li>Key status codes: <code>429</code> (throttled), <code>401</code> (unauthorized), <code>403</code> (forbidden), <code>404</code> (not found)</li>
<li>Key metrics: <code>Availability</code>, <code>ServiceApiHit</code>, <code>ServiceApiLatency</code>, <code>ServiceApiResult</code>, <code>SaturationShoebox</code></li>
<li>Known issues: <code>memory/amg-check-key-vault/report.md</code></li>
<li>Configuration: <code>memory/amg-check-key-vault/config.md</code></li>
</ul>
<h2>First-Run Setup</h2>
<p>Run only when Config shows <code>NOT_CONFIGURED</code>. After completing, return to the Workflow above.</p>
<p><strong>1. Discover Datasource UID</strong>: Call <code>amgmcp_datasource_list</code>. Filter <code>type == "grafana-azure-monitor-datasource"</code>. Prefer <code>uid == "azure-monitor-oob"</code> if multiple match. Abort if zero match.</p>
<p><strong>2. Discover Subscription ID(s)</strong>: Run this Resource Graph query to list all subscriptions with key vaults, then present the results as a table and ask the user which subscription(s) to use:</p>
<pre><code>resources
| where type == 'microsoft.keyvault/vaults'
| join kind=inner (
resourcecontainers
| where type == 'microsoft.resources/subscriptions'
| project subscriptionId, subscriptionName=name
) on subscriptionId
| summarize KeyVaults=count() by subscriptionId, subscriptionName
| order by KeyVaults desc
</code></pre>
<p>Present the results as a table with columns: <strong>Subscription Name</strong>, <strong>Subscription ID</strong>, <strong>Key Vaults</strong>. Then ask the user: <em>"Which subscription ID(s) should I configure for this health check?"</em></p>
<p><strong>3. Write config</strong>: Write <code>memory/amg-check-key-vault/config.md</code>:</p>
<pre><code class="language-markdown"># amg-check-key-vault Configuration
User-specific values for the Key Vault health check skill.
This file is auto-generated on first run and can be edited manually.
Azure Monitor Datasource
- **UID**: {discovered_uid}
- **Name**: {discovered_name}
Subscriptions
- {subscription_id_1}
- {subscription_id_2}
</code></pre>
<p><strong>4. Confirm</strong>: Show the resolved config and ask for confirmation before proceeding.</p>




