Active Directory
banshee/active-directory-collection/active-directory/winrm/
dns-server
The DNS Server service of a Windows and the state of each of its zones, by WinRM and PowerShell
by banshee1 installation2 versions
// The DNS Server of Windows, by WinRM: the state of its service, and of each zone it hosts, running, paused,
// or shut down (a secondary copy that expired). Whether a name resolves is network/dns/resolution of
// banshee/network-collection.
// Runs one PowerShell script that only reads: Win32_Service for the service DNS, then, when it runs, the WMI
// class MicrosoftDNS_Zone (namespace root\MicrosoftDNS), which Microsoft documents: Name, Paused, Shutdown.
// The script is the one of active-directory/ssh/dns-server, without the powershell -Command "..." that
// cmd.exe needs there.
need('protocol:winrm');
output('service', 'text', array('label' => 'DNS Server service'));
per('zone', 'Zones');
output('state', 'text', array('label' => 'State', 'per' => 'zone'));
watch.expect('service-stopped', 'DNS Server stopped', 'service', array('critical' => array('running')));
watch.state('zone-down', 'Zone not served', 'state', array('warning' => array('paused'), 'critical' => array('shutdown')));
watch.missing('missing', 'Zone missing', 'state');
$read = winrm.run("$ErrorActionPreference = 'Stop'; "
. "[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding; "
. "$state = [string](Get-CimInstance Win32_Service -Filter 'Name=''DNS''').State; "
. "$zones = @(); "
. "if ($state -eq 'Running') {"
. " $zones = @(Get-CimInstance -Namespace root/MicrosoftDNS -ClassName MicrosoftDNS_Zone"
. " | Select-Object Name, Paused, Shutdown) }; "
. "ConvertTo-Json -Compress -Depth 4 -InputObject @{service = $state; zones = $zones}");
$answer = text.trim($read['output']);
if (list.count(text.match($answer, '^\{')) == 0) {
fail('misconfigured', 'PowerShell did not return the DNS Server', $answer . $read['errors']);
}
$dns = json.read($answer);
if ($dns['service'] == '') {
fail('misconfigured', 'The DNS Server service is not installed', $answer);
}
// The state of the service is written by WMI in English: "Running", "Stopped", "Start Pending"...
value('service', text.lower(text.join(text.words($dns['service']), '-')));
foreach ($dns['zones'] as $zone) {
$state = 'running';
if ($zone['Paused']) {
$state = 'paused';
}
if ($zone['Shutdown']) {
$state = 'shutdown';
}
value('state', $state, $zone['Name']);
}