feat: add Stats (database) functions - #89
Merged
Merged
Conversation
Remove-PiHoleCurrentAuthSession (called from every public function's finally block to close its session) called Invoke-RestMethod without suppressing its result, so whatever that DELETE call returned became an extra element appended to the calling function's own output. This turned every function's return value into a 2-element array (the real result plus an empty string) instead of the single object the API docs describe. Property access on the result silently filtered it out (accessing a missing property across a collection drops elements that lack it), so existing formatted output looked fine by accident, but RawOutput consumers and anything checking result shape got the polluted array. Discovered while writing tests for the new database-stats functions, where -RawOutput $result.PSObject.Properties.Name exposed the leak. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds the six missing "Stats (database)" API operations identified earlier: the live /stats/upstreams endpoint (the only live stat that had no function yet) plus the five long-term-database equivalents of the existing live stats functions (summary, upstreams, top domains, top clients, query types). The database-backed endpoints require mandatory From/Until Unix-timestamp parameters, matching the API spec (fetched directly from the server's /api/docs/specs/stats.yaml). New functions: - Get-PiHoleStatsUpstream - Get-PiHoleStatsDatabaseUpstream - Get-PiHoleStatsDatabaseSummary - Get-PiHoleStatsDatabaseTopDomain - Get-PiHoleStatsDatabaseTopClient - Get-PiHoleStatsDatabaseQueryType All follow the module's standard try/catch/finally + session cleanup pattern and are registered in the export list. Regenerated the README command reference to include them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
feat: add Stats (database) functions
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.
Summary
Fills in the "Stats (database)" gap from the earlier API coverage audit: 6 new functions in
Metrics.Get-PiHoleStatsUpstream— the live/stats/upstreamsendpoint (the only live stat that had no function yet)Get-PiHoleStatsDatabaseUpstream,Get-PiHoleStatsDatabaseSummary,Get-PiHoleStatsDatabaseTopDomain,Get-PiHoleStatsDatabaseTopClient,Get-PiHoleStatsDatabaseQueryType— long-term (on-disk) equivalents of the existing live stats functions, each requiring mandatoryFrom/UntilUnix-timestamp parameters per the API specAll follow the module's standard try/catch/finally + session-cleanup pattern, are registered in the export list, and the README command reference has been regenerated to include them.
Also fixed: a module-wide output-leak bug
Remove-PiHoleCurrentAuthSession(called from every public function'sfinallyblock) never suppressed its ownInvoke-RestMethodresult, so that response leaked into the calling function's output stream — turning every function's return value into a 2-element array (real result + a trailing empty string) instead of a single object. Affected the whole module, not just the new functions; confirmed by reproducing it on the pre-existingGet-PiHoleStatsSummarytoo. Fixed with a one-line$null =suppression.Test plan
Get-PiHoleStatsSummary, confirmed the fix resolves bothInvoke-ScriptAnalyzer -Path .\PiHoleShell -Recurse— no findingsInvoke-Pester -Path .\testsrun — 29 passed, only the pre-existing unrelatedSet-PiHoleDnsBlockingfailure remains🤖 Generated with Claude Code