Windows DNS Server 2016 and 1709+ Zone Query Statistics Datasource
Microsoft.Windows.DNSServer.2016.DNSServerZoneQueryStatistics.DS (DataSourceModuleType)
Provides data for queries statistics monitors and rules
Element properties:
Member Modules:
Overrideable Parameters:
Source Code:
<DataSourceModuleType ID="Microsoft.Windows.DNSServer.2016.DNSServerZoneQueryStatistics.DS" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SyncTime" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PS" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>DNSServer2016ZoneQueryStatisticsDS</ScriptName>
<ScriptBody><Script>
param ([String] $PrincipalName)
$SCRIPT_NAME = "DNSServer2016ZoneQueryStatisticsScript"
$ErrorActionPreference = "Stop"
# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4
# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3
# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"
$momAPI = new-object -comObject MOM.ScriptAPI
$DNS_NOT_RUNNING_EVENT_ID = 7654
$DNS_NOT_RUNNING_SCRIPT_MESSAGE = "DNS Server Service is not running. Exiting."
$ErrorInfo = 5704
$EventWarn = 5702
$EventError = 5702
$EventSuccess = 5700
function FuncCheckService{
param($ServiceName)
try
{
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "running")
{
return $false
}
return $true
}
catch
{
return $false
}
}
Function Set-Error($momAPI,[String]$ErrorMessage,$EventLevel,$EventType,[String]$ScriptName)
{
if ($null -eq $momAPI)
{
return
}
try
{
if ($null -ne $momAPI)
{
$momAPI.LogScriptEvent($ScriptName,$EventLevel,$EventType,$ErrorMessage)
}
}
catch
{
}
}
Function Import-CmdLets ($momAPI,[string]$ScriptName)
{
try
{
$dnsmodule = Get-Module -Name "DnsServer"
if ($null -eq $dnsmodule)
{
Import-Module DnsServer
}
}
catch [System.IO.FileNotFoundException]
{
$ErrorMessage = "Dns cmdlets doesn't exist."
Set-Error -momAPI $momAPI -ScriptName $ScriptName -EventLevel $EventError -EventType $EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage
exit
}
catch
{
$ErrorMessage = Get-ErrorMessage -Exception $_.Exception -ScriptName $ScriptName
Set-Error -momAPI $momAPI -ScriptName $ScriptName -EventLevel $EventError -EventType $EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage
exit
}
}
Function Get-ErrorMessage($Exception,[string]$ScriptName)
{
$ErrorMes = $Exception.Message
$ErrorMessage = @"
Module: $ScriptName
Error(s) was(were) occurred:
Error(s):
$ErrorMes
"@
return $ErrorMessage
}
Function Process-DiscoveryFailure
{
$ErrorMessage = Get-ErrorMessage -Exception $_.Exception -ScriptName $Script:SCRIPT_NAME
Set-Error -momApi $Script:momApi -ScriptName $Script:SCRIPT_NAME -EventLevel $Script:EventError -EventType $Script:EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage
$discoveryData = $Script:momApi.CreateDiscoveryData(0, $Script:ElementID, $Script:TargetID)
$discoveryData.IsSnapshot = $false
$discoveryData
}
Import-Cmdlets -momAPI $momAPI -ScriptName $SCRIPT_NAME
if (-Not (FuncCheckService "DNS"))
{
$momAPI.LogScriptEvent($SCRIPT_NAME, $DNS_NOT_RUNNING_EVENT_ID, $EVENT_TYPE_ERROR, $DNS_NOT_RUNNING_SCRIPT_MESSAGE)
return
}
$zones = @()
$zones += get-DnsServerZone -ComputerName $PrincipalName | Where {$_.ZoneType -eq "Primary" -or $_.ZoneType -eq "Secondary"}
if ($zones -ne $null -and $zones.Count -gt 0)
{
foreach ($zone in $zones)
{
for ($i = 1; $i -le 10; $i++)
{
try{
$allStatistics = Get-DnsServerStatistics -ZoneName $zone.ZoneName -ComputerName $PrincipalName
[double]$QueriesReceived = 0
[double]$QueriesFailure = 0
[double]$QueriesNameError = 0
$zoneQueryStatistics = @()
$zoneQueryStatistics += $allStatistics.ZoneQueryStatistics
if ($zoneQueryStatistics -ne $null -and $zoneQueryStatistics.Count > 0)
{
foreach ($zoneQueryStat in $zoneQueryStatistics)
{
$QueriesReceived += $zoneQueryStat.QueriesReceived
$QueriesNameError += $zoneQueryStat.QueriesNameError
$QueriesFailure += $zoneQueryStat.QueriesFailure
}
}
$bag = $momAPI.CreatePropertyBag()
$bag.AddValue("ServerName", $PrincipalName)
$bag.AddValue("ZoneName", $zone.ZoneName)
$bag.AddValue("QueriesReceived", $QueriesReceived)
$bag.AddValue("QueriesNameError", $QueriesNameError)
$bag.AddValue("QueriesFailure", $QueriesFailure)
$bag
break
}
catch
{
Start-Sleep -Seconds 1
}
}
}
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PS">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>