Network Adapters DNS Servers Monitor Data Source

Microsoft.Windows.Server.2012.R2.AD.Configuration.NetworkAdapters.DNS.DataSource (DataSourceModuleType)

Data Source for the Network Adapters DNS Servers monitor.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds
ErrorThresholdint$Config/ErrorThreshold$Threshold that must be exceeded to trigger an error alert.
WarnThresholdint$Config/WarnThreshold$Threshold that must be exceeded to trigger a warning alert.

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.2012.R2.AD.Configuration.NetworkAdapters.DNS.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ErrorThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WarnThreshold" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="ErrorThreshold" Selector="$Config/ErrorThreshold$" ParameterType="int"/>
<OverrideableParameter ID="WarnThreshold" Selector="$Config/WarnThreshold$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/NetworkAdapterDnsCheck.vbs$ $Config/ErrorThreshold$ $Config/WarnThreshold$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>NetworkAdapterDnsCheck.vbs</Name>
<Contents><Script>'*************************************************************************
' Script Name - Network Adapter DNS Check
'
' Purpose - Monitors the DNS servers on the network adapters
'
' (c) Copyright 2014, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

On Error Resume Next

SetLocale("en-us")

Sub Main()

Dim oParams, oAPI, oBag, oWMI, oAdapters, oAdapter, oPing, oStatus, sError, sGoodList, sErrorList
Dim iTotalAdapters, iWarnAdapters, iBadAdapters, iErrorThreshold, iWarnThreshold, i, sAdapterError, iGoodTotal

Set oParams = WScript.Arguments
Set oAPI = CreateObject("Mom.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

if oParams.Count &lt;&gt; 2 then
sError = "The number of command line arguments is incorrect: " &amp; vbCrLf &amp; _
"Expected: 2" &amp; vbCrLf &amp; _
"Actual: " &amp; oParams.Count

oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", sError

Call oAPI.Return(oBag)
Exit Sub
End if

iErrorThreshold = CInt(oParams(0))
iWarnThreshold = CInt(oParams(1))
iTotalAdapters = 0
iBadAdapters = 0
iWarnAdapters = 0

Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set oAdapters = oWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each oAdapter in oAdapters
sAdapterError = ""
sGoodList = ""
sErrorList = ""
iTotalAdapters = iTotalAdapters + 1
If Not IsNull(oAdapter.DNSServerSearchOrder) Then
iGoodTotal = 0
For i = 0 To UBound(oAdapter.DNSServerSearchOrder)
Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" &amp; oAdapter.DNSServerSearchOrder(i) &amp; "'")

For Each oStatus in oPing
If not IsNull(oStatus.StatusCode) and oStatus.StatusCode = 0 Then
iGoodTotal = iGoodTotal + 1
sGoodList = sGoodList + oAdapter.DNSServerSearchOrder(i) + vbCrLf
Else
sErrorList = sErrorList + oAdapter.DNSServerSearchOrder(i) + vbCrLf
End If
Next
Next

sAdapterError = "-----------------------------------------" &amp; vbCrLf &amp; _
oAdapter.Description &amp; vbCrLf &amp; vbCrLf &amp; _
"Responding to pings:" &amp; vbCrLf &amp; _
sGoodList &amp; vbCrLf &amp; _
"Not responding to pings:" &amp; vbCrLf &amp; _
sErrorList &amp; vbCrLf &amp; vbCrLf

if (iGoodTotal &lt; iErrorThreshold) Then
iBadAdapters = iBadAdapters + 1
sError = sError &amp; sAdapterError
Elseif (iGoodTotal &lt; iWarnThreshold) Then
iWarnAdapters = iWarnAdapters + 1
sError = sError &amp; sAdapterError
End If
End If
Next

if (iBadAdapters &gt; 0) Then
sError = "The number of DNS servers on the network adapaters that are responding to ping requests is below the configured error threshold:" &amp; vbCrLf &amp; _
"Number of adapters: " &amp; iTotalAdapters &amp; vbCrLf &amp; _
"Available DNS servers threshold: " &amp; iErrorThreshold &amp; vbCrLf &amp; vbCrLf &amp; sError

oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", sError
Elseif (iWarnAdapters &gt; 0) Then
sError = "The number of DNS servers on the network adapaters that are responding to ping requests is below the configured warning threshold:" &amp; vbCrLf &amp; _
"Number of adapters: " &amp; iTotalAdapters &amp; vbCrLf &amp; _
"Available DNS servers threshold: " &amp; iWarnThreshold &amp; vbCrLf &amp; vbCrLf &amp; sError

oBag.AddValue "State", "WARN"
oBag.AddValue "ErrorString", sError
Else
oBag.AddValue "State", "GOOD"
End If

Call oAPI.Return(oBag)
End Sub

Call Main()
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>