Repository navigation
Report: name failed collectors, count consolidated subscriptions - #51
Merged
stefoy merged 11 commits intoNov 25, 2026
Merged
Conversation
added 3 commits
October 27, 2026 20:41
When a collector throws, its resource type is written as an empty array and dropped from the HTML report, which then reads the same as a subscription that has none of that type. The run carries on and exits 0, and the only mention of the failure is a console line in the middle of the run. ResourceInventory.ps1 now keeps this run's collector failures in a script-scoped list, because $Global:CollectorFailures is a running total across every subscription of a Run-AllSubscriptions run, and passes it to Extension/Summary.ps1 as -CollectorFailures. Summary.ps1 shows an "Incomplete collection" banner naming the missing resource types, adds a note next to Service Types, and ends its console output with a "Collection INCOMPLETE" line. Nothing changes when no collector failed. Exit codes are unchanged. Tests/CollectorFailureBanner.Tests.ps1 runs the real Summary.ps1 on a small inventory with and without failures.
A direct ResourceInventory.ps1 run in which one or more collectors failed writes the full report and zip, and used to exit 0. It now exits 4, the code Run-AllSubscriptions.ps1 already uses for collector failures, once the zip exists. A run that wrote no zip keeps its exit code. Under -RunAllSubs nothing changes: every wrapper call site treats a non-zero exit as a failed subscription, and the wrapper reports collector failures through its own exit code. README documents the direct run's exit codes next to the wrapper's table. Tests/DirectRunExitCode.Tests.ps1 runs the real script with offline stand-ins for Azure.
A direct run that checks read access up front through Resource Manager before any collector runs found no answer for those calls in the harness, so every direct run stopped with exit 1 before collection. The harness now answers the token, role assignment, role definition and permissions requests as for a Reader assignment on the subscription, so the subscription is readable and the run reaches the collectors. Any other Resource Manager call fails in the harness. A run without that check makes none of these calls, so the test passes with or without it.
This was referenced Oct 28, 2026
… report The report of a subscription with no resources read 'Total Resources:' with nothing after it, and 'Subscription: (unknown)', in the HTML in the output folder and in the copy in the zip. Summary.ps1 summed the per-type record counts with Measure-Object, which gives no sum for no input; the total is now 0 then, in the header and in the console line. Summary.ps1 also took the subscription name from the first record, and ResourceInventory.ps1 did not pass -SubscriptionName. A run of one subscription now passes that subscription's name, the way the tenant id is passed. Under -Obfuscate, and for a run of several subscriptions, the name is still taken from the first record, so an obfuscated report keeps its masked name and an empty obfuscated report shows '(unknown)' rather than the real name.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 30, 2026
…om a direct run when one failed # Conflicts: # README.md # ResourceInventory.ps1
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 30, 2026
…wslabs#59/awslabs#61/awslabs#64/awslabs#53/awslabs#56): run the offline harnesses on the Az PowerShell path The child-process harnesses of these PRs answered sign-in, the subscription list and Resource Graph through an 'az' stand-in. awslabs#66 drops the Azure CLI, so that stand-in is never called. Tests/Helpers/AzPsStandIns.ps1 now gives every harness Get-AzSubscription, Get-AzAccessToken -TenantId, a signed-in context and Resource Graph paging through Invoke-AzRestMethod with skip tokens, and answers each page from the harness's own graph stand-in (renamed Invoke-StandInGraph). Discovery queries go through Invoke-DiscoveryGraphQuery (awslabs#59), so the -HideRawOutput check reads those calls. awslabs#59's unparsable page is now a cut-off page (an empty property name is kept since awslabs#66), and awslabs#52's setup stop is shown with a missing Az module instead of a missing Azure CLI.
added 6 commits
November 9, 2026 10:13
A direct run without -SubscriptionID inventories every subscription the sign-in lists into one report, but its header read 'Subscription: <name>' with one subscription's name: Summary.ps1 took it from the first record. For a run over more than one subscription the header now reads 'N subscriptions (consolidated)'. A count says nothing that -Obfuscate would mask, so it is used under -Obfuscate too. A run with -SubscriptionID, or of one subscription, is unchanged. The new test runs the real script against offline stand-ins for the Azure CLI and the Az cmdlets: two subscriptions without -SubscriptionID (with and without -Obfuscate), two with -SubscriptionID, and one without, under en-US and tr-TR (the one-subscription case under en-US only: on this base a tr-TR run loses the record's subscription name before this code is reached).
The header test carried its own copy of the offline stand-ins for the Azure CLI and the Az cmdlets. It now runs the real script through the shared Tests/Helpers/InnerRunHarness.ps1, added here unchanged, so the stand-ins live in one place. The cases and what they check are the same.
The 'N subscriptions (consolidated)' header counted every entry of the subscription list, so an entry whose state is not Enabled would be counted as covered. The count now keeps only entries whose state is exactly 'Enabled', the same filter 'az account list' applies by default when it builds that list. Under -TenantID the list is already narrowed to that tenant before the count, so another tenant's subscription is not counted. The header test gains three runs through a small local stand-in that adds entries to the subscription list only: a Disabled and a Warned entry next to two Enabled ones, a Disabled entry next to one Enabled one, and another tenant's subscription under -TenantID.
The analyzer's brace-placement rule flagged three case tables in the header test. Only the layout changes.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Nov 17, 2026
…m-pr/collector-incomplete-banner)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #22: the report now says which resource types are missing because their collector failed, and a direct run that
lost a collector exits
4instead of0. The fourth commit fixes the same header for a subscription with no resources,which showed no number after
Total Resources:and(unknown)as the subscription. The latest update makes a report thatcovers several subscriptions say how many it covers (see Update below).
Problem
When a collector under
Services/throws,ResourceInventory.ps1catches it, records it in$Global:CollectorFailuresandcarries on with the next collector. The failed resource type is written to the Inventory JSON as an empty array, so
Extension/Summary.ps1drops its section from the HTML report, the same as for a subscription that has none of that type. Therun exits
0. The person who reads the report has no way to tell that a resource type is missing.Reproduced on
mainwith a direct run on a test subscription where the VMSS collector fails (the date bug that #39 fixes):Collector FAILED: VMSS: Cannot convert null to type "System.DateTime".andThe rest of the inventory will continue, but the 'VMSS' resource type is MISSING from this report ...HTML report written: <out>/ResourcesReport_<timestamp>.html,Total resources: <n> across 9 service type(s), exit code0. Nothing at the end repeats the failure.VMSS,FAILED,MISSINGorincomplete.The Diagnostics log in the zip already names the collector on
main(
Collector failures: 1followed by[sub <guid>] VMSS: Cannot convert null to type "System.DateTime".), andRun-AllSubscriptions.ps1already lists collector failures in its final summary. What was missing is the per-subscriptionHTML report and the end of that report's console output.
The same header had a second gap. For a subscription with no resource that the collectors report, for example a new or
emptied subscription, the header of the HTML report, in the output folder and in the copy in the zip, read:
and the console line read
Total resources: across 0 service type(s).Extension/Summary.ps1sums the per-type recordcounts with
Measure-Object, which gives no sum for no input, and takes the subscription name from the first record, ofwhich there is none.
ResourceInventory.ps1does not pass-SubscriptionName. Reproduced onmainand on the third commitof this branch, offline, with the real
ResourceInventory.ps1(default metrics and consumption phases) and stand-ins for theAzure CLI and Az calls answering for a subscription with no resources.
Change
ResourceInventory.ps1: the collectorcatchblock also adds the failure to$script:CollectorFailuresThisRun, which isset to
@()next to$script:PhaseTimingsat the start of each run, andProcessSummarypasses it toSummary.ps1as-CollectorFailures. A separate list is needed because$Global:CollectorFailuresis a running total across everysubscription of a
Run-AllSubscriptions.ps1run (sequential and-ParallelStreamsboth callResourceInventory.ps1with&once per subscription), so passing it would show one subscription's failures in the next subscription's report.
Extension/Summary.ps1: new optional-CollectorFailuresparameter (objects with aModuleproperty, the shapeResourceInventory.ps1already records). When it holds at least one record, the report shows, under the privacy banner, in theexisting
coverage-bannerstyle:The header's Service Types value gets
(collection incomplete, see below), and the summary's console output ends withCollection INCOMPLETE: 1 resource type(s) missing because the collector errored: VMSS. Each type is listed once, sorted,and HTML-escaped; a record with no
Moduleis shown as(unnamed collector)so it cannot hide the banner. With no failures,or when
Summary.ps1is run on its own without the parameter, the report is unchanged.Exit code (second commit). A direct
ResourceInventory.ps1run, meaning one without-RunAllSubs, now exits4whenthis run recorded at least one collector failure and its zip was written. Before, it exited
0.4is the codeRun-AllSubscriptions.ps1already uses for "one or more collectors failed". I decided this. There is no switch to keep0. Every other direct run ends as before:0with no collector failure,1from the pre-flight checks. A run thatwrote no zip keeps its old exit code, because
4promises a written report.Under
-RunAllSubsthe new exit is skipped. All three places the wrapper callsResourceInventory.ps1(the sequentialloop and the one-subscription fallback of
-ParallelStreamsinRun-AllSubscriptions.ps1, and the stream worker inRun-AllSubscriptions.Stream.ps1) treat any non-zero exit as a failed subscription, so a4there would turn acompleted subscription into a failed one. The wrapper's per-subscription status, its summary and its own exit codes are
unchanged.
README.md: a table of the direct run's exit codes (0,1,4) under the wrapper's table. The wrapper's rows areunchanged.
Empty-subscription header (fourth commit).
Extension/Summary.ps1: with no records the total is0, in the header andin the console line.
ResourceInventory.ps1: a run of one subscription (-SubscriptionID) without-Obfuscatepassesthat subscription's name from the subscription list to
Summary.ps1as-SubscriptionName, the way the tenant id ispassed. For a subscription with records this is the name the first record already carried. Under
-Obfuscate, and for arun over several subscriptions (no
-SubscriptionID), the name is still taken from the first record, so an obfuscatedreport keeps its masked name and an empty obfuscated report shows
(unknown)rather than the real name. No column, exitcode or stop changes.
Testing
Tests/CollectorFailureBanner.Tests.ps1(8 tests). It runs the realSummary.ps1on a small generated inventory andchecks the HTML and the console output: one failure, several failures (deduplicated and sorted), a record with a blank
Module, an HTML-escaped name, the console line at the end, and no banner or line when the parameter is omitted, empty or holdsonly
$null. Onmain5 fail and 3 pass (the three no-failure cases); on this branch all 8 pass.Tests/DirectRunExitCode.Tests.ps1(9 tests). It copies the script to a temporary folder, adds small collectors there(one returns a record, the others throw) and runs the real
ResourceInventory.ps1in a childpwshwith-SkipMetrics -SkipConsumptionand offline stand-ins for the Azure CLI and Az calls. It checks: one failing collector ->report and zip written, banner names it, exit
4; no failure -> exit0;-Servicematching nothing -> still exit1;five failing collectors in a row (no zip) -> not
4; under-RunAllSubswith a failing collector -> exit0, and each ofthe three wrapper call sites still has the same
$LASTEXITCODEcheck, which does not throw for that0. Onmain7 passand 2 fail (the banner and
Expected 4, but got 0.); on the first commit of this branch 8 pass and only the exit4testfails; from the second commit on, all 9 pass. The harness also stands in for the up-front read-access check that Check read access and usage values up front for every subscription #38 adds (the
token, role assignment, role definition and permissions requests answer as for a Reader assignment on the subscription, and
any other Resource Manager call fails), so the test passes with or without Check read access and usage values up front for every subscription #38.
Tests/EmptySubscriptionReport.Tests.ps1(8 tests). It copies the script to a temporary folder and runs the realResourceInventory.ps1in a childpwshwith the default metrics and consumption phases and offline stand-ins for theAzure CLI and Az calls: for a subscription with no resources, without and with
-Obfuscate, and for one with a single disk.It reads the header of the report in the output folder and of the copy in the zip, and the console line. On
mainand onthe third commit of this branch 2 pass and 6 fail (
Expected: '0'/But was: ''for Total Resources,Expected: 'Demo Subscription'/But was: '(unknown)'for the subscription); on the fourth commit all 8 pass. Theobfuscated case checks that the real subscription name appears nowhere in either copy of the report. The one-disk report
is the same before and after the fourth commit apart from its
Generated:time.main269 passed / 162 failed / 22 skipped; first commit 277 / 162 / 22; second and third commits 286 / 162 / 22;fourth commit 294 / 162 / 22, the same failing tests each time. PSScriptAnalyzer with the repository settings and the
workflow's paths: nothing new; on the third and fourth commits its only result is the same existing warning in
Tests/RecoveryMerge.Tests.ps1.HTML report and the copy in the zip both show the banner naming
VMSS, Service Types reads9 (collection incomplete, see below), the summary's console output ends with theCollection INCOMPLETEline, and theexit code is
4.Run-AllSubscriptions.ps1 -SkipMetrics -SkipConsumptionover three test subscriptions (read-only; the wrapper chose-ParallelStreams 2, so the stream worker made the calls), once on the first commit and once on the second: the sameresult both times. All 3 subscriptions processed,
3 zip(s) match 3 successful sub(s),0 failed, the VMSS failure listedunder
Collector Failures, theFAILED (collectors)banner, and wrapper exit code4.Run-AllSubscriptions.ps1calls the script with
-SubscriptionIDfor each subscription, so its per-subscription reports take the same code path;a wrapper run was not made for this commit.
git merge-treeagainst the current head of each other open PR: Check read access and usage values up front for every subscription #38 conflicts inResourceInventory.ps1andREADME.md,because both add lines at the end of the script and below the wrapper's exit-code table. Whichever merges second keeps both
sides, with this PR's
exit 4as the script's last statement. The fourth commit's lines merge outside those conflicts.Exit 2 from a direct run that wrote no report #52 conflicts in
README.md, where both add a section for the direct run's exit codes under the wrapper's table. Theother open PRs merge cleanly. Mask a parent's name inside the obfuscated id of a child resource #53 also changes
Extension/Summary.ps1(the obfuscation token pattern) and merges cleanly.Update: how many subscriptions a consolidated report covers
A direct run without
-SubscriptionIDthat covers more than one subscription now showsN subscriptions (consolidated)in the report header, instead of the name of whichever subscription came first. Onlysubscriptions whose state is
Enabledare counted, the same filter the run uses to choose what it inventories. A countreveals nothing, so the same header is used under
-Obfuscate. A run with-SubscriptionID, or of one subscription, isunchanged. Only
ResourceInventory.ps1changes; no inventory, consumption or metrics field changes.Tested offline with the real script: new
Tests/MultiSubscriptionHeader.Tests.ps1runs it in a childpwshwith stand-insfor the Azure calls, for two subscriptions with and without
-SubscriptionID, a disabled subscription,-Obfuscate, anden-US and tr-TR. On the previous head of this PR 6 fail (the header and the disabled subscription); on this head all pass.
The tr-TR case of the subscription name is skipped: on main a tr-TR run loses the record's subscription name before this
code runs, which #66 fixes. Not run on Azure, and not run on Windows.
How to test
Quick check (no Azure)
Needs PowerShell 7 and Pester 5 (
Install-Module Pester -MinimumVersion 5.0 -Scope CurrentUser). The tests write only to atemporary folder.
From the repository root:
main:Tests Passed: 12, Failed: 13, for exampleExpected regular expression '<b>Incomplete collection:</b> 1 resource type\(s\) could not be collected and are MISSING from this report' to match '<!DOCTYPE html>,for the console line
Expected: ' Collection INCOMPLETE: 2 resource type(s) missing because ...'/But was: ' Privacy posture: identifiable (contains real names; treat ...', for the exit codeExpected 4, but got 0., and for the empty subscription's headerExpected: '0'/But was: ''andExpected: 'Demo Subscription'/But was: '(unknown)'.Tests Passed: 25, Failed: 0.(Of these steps, the two
Invoke-Pestercommands were run as written, on local exports ofmainwith the three test filesand of this branch; the
git fetchof the PR head and the worktree steps were not.)Reproduce on Azure (read-only)
Needs a test subscription where a collector fails. Until #39 is merged, one empty Flexible scale set is enough: #39's
"How to test" shows how to create one at no cost (
az vmss create ... --orchestration-mode Flexiblewith no image). NeedsPowerShell 7 with the Az modules signed in (
Connect-AzAccount) and the Azure CLI signed in (az login). The run only readsfrom Azure.
main: theCollector FAILED: VMSSline in the middle of the run, nothing about it in the HTML report or afterTotal resources:, andexit code: 0.Incomplete collection:banner in<out>/ResourcesReport_<timestamp>.html,Collection INCOMPLETE: 1 resource type(s) missing because the collector errored: VMSSafter thePrivacy posture:line, andexit code: 4.Delete the scale set and its resource group afterwards.
Not changed
Run-AllSubscriptions.ps1andRun-AllSubscriptions.Stream.ps1: no edits. Under-RunAllSubsthe inner script ends asbefore, and the wrapper's exit codes (
4for collector failures) are unchanged.no report or zip is produced, and the run ends with
0as before this PR. The new4does not fire there because no zipwas written. Giving that case its own exit code is a separate change.
ResourceInventory.ps1still prints its packaging and timing lines (Compressing Resources Output,Execution Time, ...)after the summary, so the
Collection INCOMPLETEline ends the summary block, not the whole console output.full status list of every collector with its resource count. Step 1 (a
try/catchinside each collector, with the innerexception and the record being processed) and step 3 (replacing the global
$ErrorActionPreference = "silentlycontinue"withper-call handling) are not part of this change.