sqlinsight-pro/src/SQLInsight.Servers/Synthetic/ax-logon.ps1
Søren Eggert Lundsteen Olsen 7082b278e3 Collection: Windows servers over CIM (WS-Man, DCOM fallback) and synthetic check runners
New project SQLInsight.Servers:
- CimWindowsServerSource (Microsoft.Management.Infrastructure, the API behind
  Get-CimInstance): WS-Man first, DCOM if that fails, a local session for the
  agent's own computer, as the agent's identity. Only SELECT queries (CimQueries)
  and Task Scheduler's read-only GetInfo. CPU and paging from raw counters, disks
  (Win32_Volume, Win32_LogicalDisk fallback), services, scheduled tasks, and the
  System/Application logs through the Event Log service (MS-EVEN6, XPath filter on
  the server) with Win32_NTLogEvent as fallback.
- ServerErrors: access denied, missing namespace, RPC/WinRM unreachable and
  timeouts become "ikke målbar" reasons that name the missing right and the grant
  script; never local administrator.
- WindowsServerTester: tries every area once for the web UI's test.
- SyntheticCheckRunner: TCP, HTTP(S) with expected status/text and TLS certificate
  expiry (also for refused certificates), SQL login + read-only query (re-validated,
  in a transaction that is always rolled back), DNS, and the Dynamics AX logon:
  AOS port, then a logon through the .NET Business Connector in a separate Windows
  PowerShell process with a timeout when it is installed; otherwise the result
  says clearly that only the port was tested.

Tests: error mapping, queries, AX command/parsing, runners against local TCP and
HTTP(S) servers with a self-signed certificate, the CIM source against this
computer, and the SQL check against the test instance.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 14:58:18 +02:00

24 lines
1.4 KiB
PowerShell

# SQLInsight Pro: logon to Dynamics AX through the .NET Business Connector, run by the agent in its own process.
# Logs on as the agent's Windows account, logs off again, and writes one line: SQLINSIGHT-AX-OK <ms> or SQLINSIGHT-AX-ERROR <text>.
# Reads nothing in AX and changes nothing. Parameters come in environment variables (no quoting problems):
# SQLINSIGHT_AX_DLL path to Microsoft.Dynamics.BusinessConnectorNet.dll
# SQLINSIGHT_AX_COMPANY company (DataAreaId), or empty for the user's default
# SQLINSIGHT_AX_SERVER object server, e.g. 01@aos01:2712 or aos01:2712
# SQLINSIGHT_AX_CONFIG AX client configuration, or empty
$ErrorActionPreference = 'Stop'
function Value([string] $name) { $v = [Environment]::GetEnvironmentVariable($name); if ([string]::IsNullOrEmpty($v)) { return $null } else { return $v } }
try {
Add-Type -Path (Value 'SQLINSIGHT_AX_DLL')
$ax = New-Object Microsoft.Dynamics.BusinessConnectorNet.Axapta
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$ax.Logon((Value 'SQLINSIGHT_AX_COMPANY'), $null, (Value 'SQLINSIGHT_AX_SERVER'), (Value 'SQLINSIGHT_AX_CONFIG'))
$ms = $watch.ElapsedMilliseconds
try { [void] $ax.Logoff() } catch { }
Write-Output ('SQLINSIGHT-AX-OK ' + $ms)
exit 0
} catch {
$e = $_.Exception
while ($e.InnerException) { $e = $e.InnerException }
Write-Output ('SQLINSIGHT-AX-ERROR ' + ($e.Message -replace '\s+', ' '))
exit 1
}