wulf-pulse/lib/services/rmm/scripts/get-dhcp-scopes.ts
lorentz 1112a06afe feat: RMM Overshell, IT Glue audit/write-back, LogLift, link-aware bundles, dashboard overhaul
- RMM Overshell (migration 077): admin page, dispatch UI, executor/worker, target
  resolver, script registry (AD/DHCP/DNS/event-log/services/software/network/loglift)
- LogLift evidence pipeline (migration 078): upload webhook, B2 storage client,
  receiver/matcher, EventLogCollector PowerShell script
- IT Glue audit + write-back (migrations 075, 076): asset-audit runner, ticket
  xrefs, applications/configurations browse pages + apply/revert/audit endpoints
- Link-aware analyzer bundles (migration 073) + provider toggle (migration 074):
  link-discovery service, OpenRouter LLM provider, related-tickets/itglue-suggestion
  panels, analyze-bundle endpoint
- Endpoint data model + device-link reconciliation (migrations 079, 080): conflicts
  admin page, reconciler service, resolve endpoints
- Dashboard overhaul: integration-health service + alerts, overview/health endpoints
- Permissions: add itglue + rmm scopes; middleware: public /api/rmm/loglift route

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 07:13:18 -04:00

57 lines
2.1 KiB
TypeScript

/**
* get-dhcp-scopes — list DHCP scopes + lease statistics + reservations.
* Site-anchored. Useful for documenting subnet plans + finding stale
* reservations that should be retired.
*/
import { type RmmScript, parseJsonOutput } from './types';
export const getDhcpScopes: RmmScript = {
id: 'get-dhcp-scopes',
name: 'DHCP scopes + reservations',
description:
'All authorized DHCP servers in the domain, their scopes, scope-level statistics, and reservations.',
target_type: 'site_anchor',
expected_runtime_seconds: 60,
version: 1,
body: `
$ErrorActionPreference = 'SilentlyContinue'
Import-Module DhcpServer -ErrorAction SilentlyContinue
$servers = Get-DhcpServerInDC -ErrorAction SilentlyContinue
$result = foreach ($srv in $servers) {
$scopes = Get-DhcpServerv4Scope -ComputerName $srv.DnsName -ErrorAction SilentlyContinue
$detail = foreach ($sc in $scopes) {
$stats = Get-DhcpServerv4ScopeStatistics -ComputerName $srv.DnsName -ScopeId $sc.ScopeId -ErrorAction SilentlyContinue
$resv = Get-DhcpServerv4Reservation -ComputerName $srv.DnsName -ScopeId $sc.ScopeId -ErrorAction SilentlyContinue |
Select-Object IPAddress, ClientId, Description, Name
[pscustomobject]@{
scope_id = $sc.ScopeId.ToString()
name = $sc.Name
subnet_mask = $sc.SubnetMask.ToString()
start_range = $sc.StartRange.ToString()
end_range = $sc.EndRange.ToString()
state = $sc.State.ToString()
lease_duration_hours = $sc.LeaseDuration.TotalHours
addresses_in_use = if ($stats) { $stats.InUse } else { $null }
addresses_free = if ($stats) { $stats.Free } else { $null }
percentage_in_use = if ($stats) { $stats.PercentageInUse } else { $null }
reservations = $resv
}
}
[pscustomobject]@{
dhcp_server = $srv.DnsName
ip = $srv.IPAddress.ToString()
scopes = $detail
}
}
@{
hostname = $env:COMPUTERNAME
captured_at_utc = (Get-Date).ToUniversalTime().ToString("o")
servers = $result
} | ConvertTo-Json -Depth 6 -Compress
`.trim(),
parseOutput: (stdout) => parseJsonOutput(stdout),
};