Windows Update エージェント接続のユニット モニター

Microsoft.SystemCenter.Essentials.WUAgent.ConnectionUnitMonitor (UnitMonitor)

目的:Essentials サーバーに 10 日以内に接続しているかどうかを判断するため、Windows Update エージェントを監視します。

Knowledge Base article:

概要

このコンピューターは、10 日以内に SCE サーバーに接続していません。

原因

このコンピューターは、自動更新を行うように構成されていません。

解決方法

SCE サーバー上で製品構成ウィザードを実行します。

Element properties:

TargetMicrosoft.SystemCenter.Essentials.WUAgent
Parent MonitorSystem.Health.AvailabilityState
CategoryCustom
EnabledTrue
Alert GenerateFalse
Alert Auto ResolveTrue
Monitor TypeMicrosoft.Windows.TimedScript.TwoStateMonitorType
RemotableFalse
AccessibilityInternal
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SystemCenter.Essentials.WUAgent.ConnectionUnitMonitor" Accessibility="Internal" Enabled="onEssentialMonitoring" Target="Microsoft.SystemCenter.Essentials.WUAgent" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="false" Priority="Normal" TypeID="Windows!Microsoft.Windows.TimedScript.TwoStateMonitorType" ConfirmDelivery="false">
<Category>Custom</Category>
<OperationalStates>
<OperationalState ID="UIGeneratedOpStateId027701d98d0b4c61b852c8de59614b8b" MonitorTypeStateID="Error" HealthState="Warning"/>
<OperationalState ID="UIGeneratedOpStateId8466cc70f29e4d4cac921b3942b440f4" MonitorTypeStateID="Success" HealthState="Success"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>3600</IntervalSeconds>
<SyncTime/>
<ScriptName>CheckWUConnection.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
'*************************************************************************
' Script Name - CheckWUAgentConnection.vbs
'
' Purpose - Checks to see if computer has connected to the Essentials server within last 10 days
'
' Assumptions - Script is run as a runtime task
'
' Parameters - UpdateServer Name
'
' (c) Copyright 2006, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************
OPTION EXPLICIT
SetLocale("en-us")

CONST HKLM = &amp;H80000002
Const SCRIPT_NAME = "CheckWUAgentConnection"

Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const EVENT_ID_SCRIPT_ERROR = 1000
Const EVENT_ID_SUCCESS = 99

Dim oAPI, objArgs, oBag
Dim strWUServer, objAutoUpdate, objResults, dateLastSearch, objReg, activeTimeBias, dateSystemNow, dateUtcNow

'Create OpsMgr object
Set oAPI = CreateObject("Mom.ScriptAPI")

' Create a property bag
Set oBag= oAPI.CreatePropertyBag()

' Create an AutoUpdate object
set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")

If objAutoUpdate Is Nothing then
ScriptError "Unable to create Microsoft.Update.AutoUpdate object. " &amp; GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If

On Error Resume Next
' Get the results from AutoUpdate
set objResults = objAutoUpdate.Results

If IsNull(objResults)then
ScriptError "Unable to get results from Microsoft.Update.AutoUpdate object. " &amp; GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
Else
' Get the LastSearchSuccessDate from the Results in UTC time format
dateLastSearch = objResults.LastSearchSuccessDate

' Get the ActiveTimeBias from registry to calculate UTC time
Set objReg = GetObject("winmgmts:root\default:StdRegProv")

If objReg Is Nothing then
ScriptError "Unabled to bind to StdRegProv. " &amp; GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If

' Get current Active Time Bias from registry
objReg.GetDWORDValue HKLM, "System\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias", activeTimeBias

If IsNull(activeTimeBias) Then
ScriptError "Could not find ActiveTimeBias information needed to convert current time to UTC. " &amp; GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If

' Get current system date &amp; time
dateSystemNow = now()

' Get current UTC date &amp; time
dateUtcNow = dateAdd("n", activeTimeBias, dateSystemNow)

' Check to see if computer is contacted in last 10 days or not
If DateDiff("d",dateLastSearch,dateUtcNow) &gt; 10 then
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
Else
Call oBag.AddValue("WUConnect", "Good")
Call oAPI.Return(oBag)
Quit()
End If

End If

'******************************************************************************
Sub ScriptError(strError)
'
' Purpose: Records a script error.
'
' Parameters: strError, the description of the error to record
'
CreateEvent EVENT_ID_SCRIPT_ERROR, EVENT_TYPE_WARNING, "The script '" &amp; SCRIPT_NAME &amp; "' failed while " &amp; strError
End Sub

'******************************************************************************
Function GetErrorString(oErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'******************************************************************************
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
End If
End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

'******************************************************************************
Sub CreateEvent(lngEventID, lngEventType, strMessage)
'
' Purpose: To create a MOM event
'
' Arguments:lngEventID, the event ID
' lngEventType, the event type (see values at top of file)
' strMessage, the message text for the event
'******************************************************************************
oAPI.LogScriptEvent "Check WU Agent Config", lngEventID, lngEventType, strMessage
End Sub

'*************************************************************************
Function Quit()

WScript.Quit()

End Function
'****************************************************************************
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='WUConnect']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Bad</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='WUConnect']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Good</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>